How to upload image using raw in POSTMAN? - django

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:
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:
I get the following error though i have added MultiPartParser in Django settings:
Can anybody help to solve this problem?

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.

Related

How to get content of the post request file POSTMAN

I have a problem with sending files to some API. When I do it via my server some pdf files send correctly but some not. But when I send the same pdf via POSTMAN everything works just fine. I am not sure what is the reason (probably POSTMAN encodes it into base64 but from my server, I send it in binary - just a guess). Is there a way to get the sent request file content from postman so that I can imitate it and compare with the request on my server?

How to upload a file from a URL as multipart/form-data in Postman

I have an API endpoint that accepts multipart/form-data file upload. I managed to upload a local file to it with Postman using the File option as below:
Now how can I upload a file that is hosted at a given URL using Postman without manually downloading it and then selecting its filename as in the above screenshot? I'm hoping to somehow GET the URL, store the binary data, and upload to the endpoint, all within a Postman collection.
One of the answers from Postman community issue:
Using Postman’s pre-request script:
Download the content from URL
Convert it to binary
Assign the binary value to a dynamic variable
Use the variable within your request

Send POST json data to an url with POSTMAN not working

I have python code wrote here: https://repl.it/#AndreiCiobnic/MixedWealthyGnuassembler
I'm trying to (re)write in Postman to make a POST request to that url.
I put like:
But I got error response from that server.
How to send the data json in Postman ?

MS GRAPH API Upload v1.0 endpoint corrupts DOCX

Was trying to upload docx files through a golang server using MS graph API, and although I was able to upload pdfs, when I tried uploading docx files the files were being corrupted when sent over. If I upload the same file through the OneDrive website, there would be no problems.
To isolate the issue I tried making the API calls through postman using a link like:
https://graph.microsoft.com/v1.0/users/pqv2-dev-svc#novacoast.com/drives/{drive-id}/items/{item-id}:/filename.docx:/content
used a bearer token.
the additional header of Content-Type of which I have tried the values:
text/plain
application/x-www-form-urlencoded
application/vnd.openxmlformats-officedocument.wordprocessingml.document
and uploaded the file with the form-data option under the body tab but with no luck, the file always gets corrupted.
Any ideas?
[Resolved] Was sending file as form-data instead of binary!

facebook graph API send image message: "failed to fetch the file from the url"

Since 2018-02-22, I cannot send messages with images I uploaded to S3 to Facebook anymore.
I get the following error:
{"error":{"message":"(#100) Failed to fetch the file from the url","type":"OAuthException","code":100,"error_subcode":2018008,"fbtrace_id":"BP8L9CQBKP+"}}
Here is my test set-up:
TOKEN=<a_valid_page_token>
FBUSER=<an_fb_user_id>
URL=https://airy-layer-staging.s3.amazonaws.com/images/fd9aee26-7dd5-48cb-99c9-c4f10ec38f31.png
curl -H"Content-Type: application/json" https://graph.facebook.com/v2.6/me/messages?access_token=$TOKEN \
-d'{"recipient":{"id":"'$FBUSER'"},"message":{"attachment":{"type":"image","payload":{"url": "'$URL'"}}}}'
These URL all work fine
URL=http://rtens.org/images/avatar.jpg
URL=https://visualhunt.com/photos/s/4/anime-pet-kitty.jpg
URL=https://s3.amazonaws.com/codecademy-blog/assets/puppy-7_zps26e8a8d9.jpg
URL=https://smd-prod.s3.amazonaws.com/science-pink/s3fs-public/styles/front_page_hero_image/public/thumbnails/image/deer_duo.jpg
I've made sure that the images exist, are publicly available, and <2MB. The images are uploaded the same way as before 2018-02-22. Why does Facebook fail to fetch the file?
Thank you for your help,
Nikolas
I could solve the problem by disabling base64 encoding when uploading the image to S3.