MATLAB Answers

0

Problem using webwrite to send image through a simple REST API

Asked by Wei Chang on 27 Sep 2015
Latest activity Answered by Vinod
on 14 Oct 2016
I was trying to do image classification through a web at service at https://cloudsight.readme.io/v1.0/docs and I had no problem to use curl to retrieve token:
curl -i -X POST -H "Authorization:MY Key" \
-F "image_request[image]=@/path/to/myimage" \
-F "image_request[locale]=en-US" \
https://api.cloudsightapi.com/image_requests
However, it was not successful when I tried webwrite, it returned "HTTP 400" error.
option=weboptions('KeyName','Authorization','KeyValue','mykey')
fid = fopen('/path/to/myimage');
img = fread(fid,Inf,'*uint8');
fclose(fid);
response=webwrite('https://api.cloudsightapi.com/image_requests',...
'image_request[image]',img,...
'image_request[locale]','en-US',option);
I guess it because the function webwrite in this format doesn't support "multipart/form-data" and I need change the media type. Then I tried send data as an JSON object
option=weboptions('KeyName','Authorization','KeyValue','mykey',...
'MediaType','application/json')
data=struct('image_request[image]',im,'image_request[locale]','en-US');
response=webwrite('https://api.cloudsightapi.com/image_requests',data,option)
But the field name in Matlab struct does not allow "[". Any suggestion?

  0 Comments

Sign in to comment.

1 Answer

Answer by Vinod
on 14 Oct 2016

Here's an example that uploads any file from MATLAB to DropBox programmatically:
Hopefully you can modify this example for your needs

  0 Comments

Sign in to comment.