python - Django RestAPI- updating images through PUT method -


i having trouble updating images using django rest api. have browsed through of similar questions in stack overflow, did not help.

the error following:

exception value: __init__() got unexpected keyword argument 'files' 

views.py

@api_view(['put']) def screenshot(request,uid):     try:         details=portal.objects.get(uid=uid)     except portal.doesnotexist:         return response(status=status.http_404_not_found)      if request.method=='put':         serializer=portalimage(details, data=request.data, files=request.files)         if serializer.is_valid():             serializer.save()             return response(serializer.data,status=status.http_201_created)         else:             return response(serializer.errors,status=status.http_400_bad_request) 

serializer.py

class portalimage(serializers.modelserializer):     image=serializers.imagefield(use_url=true)     class meta:         model=portal         fields=('image',) 

models.py

image = models.imagefield(upload_to='media/') 

i use curl upload image

curl -k -x put https://localhost/screenshot/5caed0 -d "image=/path/image1.jpg"   

traceback

traceback: file "/var/www/display/env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response  132. response = wrapped_callback(request, *callback_args, **callback_kwargs) file "/var/www/display/env/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view  58. return view_func(*args, **kwargs) file "/var/www/display/env/lib/python2.7/site-packages/django/views/generic/base.py" in view  71.  return self.dispatch(request, *args, **kwargs) file "/var/www/display/env/lib/python2.7/site-packages/rest_framework/views.py" in dispatch  456. response = self.handle_exception(exc) file "/var/www/display/env/lib/python2.7/site-packages/rest_framework/views.py" in dispatch  453. response = handler(request, *args, **kwargs) file "/var/www/display/env/lib/python2.7/site-packages/rest_framework/decorators.py" in handler  50. return func(*args, **kwargs) file "/var/www/display/portal/views.py" in screenshot  57.   serializer=portalimage(details, data=request.data, files=request.files) file "/var/www/display/env/lib/python2.7/site-packages/rest_framework/serializers.py" in __init__  94. super(baseserializer, self).__init__(**kwargs)  exception type: typeerror @ /screenshot/5caed0 exception value: __init__() got unexpected keyword argument 'files' 

if you're using drf v3, should able use

serializer = portalimage(details, data=request.data) 

as mentioned in comments, files isn't valid kwarg, looking drf viewset code, there no mention of files (from experience) "just works".

also, want make sure you're setting content-type header "multipart/form-data"


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -