upload an image to Django through Rest. Possible? How?

3,226 views
Skip to first unread message

laurent feron

unread,
Sep 19, 2013, 5:25:38 AM9/19/13
to django-res...@googlegroups.com
Hello,

I use django rest framework at the server side, and phonegap/cordova at the client side using ajax/json requests. (for tests i use CURL)
Everything works well but i have a problem with the image uploading.

How i can do that? Is it possible through Rest/Json? or do i need to go through a form as usual?
if someone has an example on the client & server sides?

My model is a standard one:
photo = models.ImageField(upload_to=upload_path, null=True, blank = True)
It works well with the admin interface.

Any helps are welcome?

Regards,
Laurent


Tom Christie

unread,
Sep 19, 2013, 8:28:03 AM9/19/13
to django-res...@googlegroups.com
Hi Laurent,

Yes that's perfectly possible.  You just need to make sure to send the request using multipart form encoded data (which supports file uploads) instead of using json (which doesn't).  There should be some easily google-able examples of using curl with multipart file uploads.  These stack overflow answers look about right:


Hope that helps get you started.

  Tom

laurent feron

unread,
Sep 19, 2013, 5:06:51 PM9/19/13
to django-res...@googlegroups.com
Hi,
It works with Curl. It is just a form in fact. no more rest.
Thanks. Your links helped me.
Laurent


--
You received this message because you are subscribed to a topic in the Google Groups "Django REST framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-rest-framework/l56UM-ciNzg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-rest-fram...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages