Postman uploads file via API using raw
How do you upload a file to postman using raw mode.
I used json entry like this:
{
"inp_doc_uid": "750761691595cf3398da311004881705",
"tas_uid": "71415152859433e07c33b11085554015",
"app_doc_comment":"test upload",
"form":"@/User/images.jpg"
}
the problem was @in php was deprecated and it is now recommended to use curlFile, how to do it in json form?
Thank.
+3
source to share
1 answer
Since you are sending the image as part of JSON, you need to encode it. Base64 encoding is a good choice. On the server side, you also need to decode it.
Have a look at this answer on How to convert an image to base64 encoding? :
$imagedata = file_get_contents("/path/to/image.jpg");
$base64 = base64_encode($imagedata);
Once you have the data, you can add it to JSON:
{
"inp_doc_uid": "750761691595cf3398da311004881705",
"tas_uid": "71415152859433e07c33b11085554015",
"app_doc_comment":"test upload",
"form":"TWFuIGlzIGRpc3R..."
}
Also see Base64 reference
+1
source to share