On May 15, 5:47 am, vernomcrp <
vernom...@gmail.com> wrote:
> I try to create restful webservice that can upload image by django-
> piston, But I don't know direction to do it.
>
Hello,
I haven't answered because I haven't done this so far but today I
needed to achieve what you say. In my example I upload a single image
to a protected resource with Basic auth method for my user 'jsmith'
with curl and save it in SOME_PATH:
$ curl -u USER:PASSWORD
http://server.com/customer/jsmith/image/ -X
POST -F "image=@Desktop/me.jpg (Sure, replace with your path ;-)
And some code:
from piston.handler import BaseHandler
from piston.utils import rc
from PIL import Image
class ImageRESTHandler(BaseHandler):
allowed_methods = ('POST',)
def create(self, request, nickname):
name = request.FILES["image"].name
image = Image.open(request.FILES["image"])
image.save(SOME_PATH+name)
return rc.ALL_OK
As a homework you need to catch the exceptions and save where you
think you should.
Regards.