14

I am trying to upload an image using POSTMAN. I succeed with form-data but not with passing data in raw JSON format.

request through form-data in POSTMAN:

enter image description here

request through curl:

curl -X POST -H "Content-Type:multipart/form-data" -F "profile_image=@/home/shivani/Pictures/Wallpapers/8018.jpg" http://127.0.0.1:8000/api/users/1/image/
{"message":"Image Uploaded successfully.","profile_image":"http://res.cloudinary.com/aubergine-solutions/image/upload/v1430204993/w0oxhv6beaxd14twrxmi.jpg"}~ 

When I send request in raw as:

enter image description here

I get the following error though i have added MultiPartParser in Django settings:

enter image description here

Can anybody help to solve this problem?

Shivani Sharma
  • 697
  • 1
  • 7
  • 22
  • 1
    Well, just to specify if anyone is running into this problem that if you want to upload image using json then base64 string of image needs to be attached like `"profile_image": { "name": "72397.jpg", "content_type":"image/jpg", "file":"base64string"}` or either way is "form-data" – Shivani Sharma Oct 16 '15 at 12:31
  • 1
    I'm also having same issue now. And I need to pass basic data with image. Can you give me the code, how you are passing image with raw data. – Vinoth Kumar May 25 '17 at 07:53

1 Answers1

7

When i'm using the image upload, i encoded the image using base64,and that encoded string is passed as json string.In the backend we can decoded the string and make the image.Try this, i think it works.

Ferose
  • 384
  • 5
  • 13