Can a django piston module create a restful webservice loadable image

I am trying to reassure the server so that the image can be uploaded. Using django-piston, I can put, receive, publish information, but I don’t know how to upload the image.

+3
source share
4 answers

to a large extent.

technically this is just an http post.

0
source

On the one hand, yes. If you have image data, you can mail it to a handler who knows how to process it; if you do it right, theoretically it should be available in request.FILES for your handler. Simple HTTP.

, . AJAX , - . " ajax" , , , .

, Firefox gecko kin " " getAsBinary().

0

POST. . ( ).

PUT, , - -. , , PUT DEL . ( , POST, PUT)

:

class x_http_methodoverride_middleware():
    def process_request(self, request):
        if 'HTTP_X_HTTP_METHODOVERRIDE' in request.META:
            newMethod = request.META['HTTP_X_HTTP_METHODOVERRIDE']
            if 'PUT' == newMethod.upper():
                request.method = 'PUT'
                request.META['REQUEST_METHOD'] = 'PUT'
                request.PUT = request.POST                
            if 'DELETE' == newMethod.upper() or 'DEL' == newMethod.upper():
                request.method = 'DELETE'
                request.META['REQUEST_METHOD'] = 'DELETE'
                request.DELETE = request.POST

( http://bitbucket.org/jespern/django-piston/issue/83/use-x-http-method-override-to-override-put)

0

: http://groups.google.com/group/django-piston/browse_thread/thread/6f3f964b8b3ccf72/bd1658121bb1874c?show_docid=bd1658121bb1874c&pli=1

- request.FILES , :

def create(self, request, nickname): 
    name = request.FILES["image"].name 
    image = PIL.Image.open(request.FILES["image"]) 
    image.save(SOME_PATH+name) 
    return rc.ALL_OK 

, ImageForm :

def create(self, request, nickname):
    form = ImageForm(request.POST, request.FILES)
    if form.is_valid():
        Image.objects.create(image=form.cleaned_data['image'])
        return rc.ALL_OK
    return rc.BAD_REQUEST

: !

0

Source: https://habr.com/ru/post/1745514/


All Articles