0

I am using Computer Vision API for handwritten analysis using R. I can get the results when passing image URL. But I want to pass binary image data to the API. What is the format for that? When using the online Console for POST using this link.

Selecting 'application/octet-stream' just shows [Binary Image Data] in the request body. I have used base64 image format within [], and ["body":data] and many other ways but I get invalid image input error. Is base64 not correct? Do I need to convert to other format?

I read on web that we need to pass image as blob.

R code I am using to post is below. Currently you can see me using a url in body, how can I pass an image there from local PC storage as a blob?

APIresponse = POST(url = cogapi,content_type('application/json'),add_headers(.headers = c('Ocp-Apim-Subscription-Key' = '*************************')),body=list(url = img_url),encode = "json")
halfer
  • 19,824
  • 17
  • 99
  • 186
  • It doesn't mention about the image needing to be in base64 - have you tried posting a binary image as-is in a post operation? What code are you using to do the post? Please add that to your question. – halfer May 28 '18 at 22:02
  • Added the POST query above. Currently its application/json, and i am using a URL. I want to use image blob with application/octet-straem but dont know how to create that blob in R and then pass in above POST – Abhinav Mohan May 29 '18 at 06:13

1 Answers1

0

Here's how you would do it in cURL:

curl -H "Ocp-Apim-Subscription-Key: 0123456789abcdef0123456789ABCDEF" -H "Content-Type: application/json" "ComputerVisionUrl" --data-binary @C:/Pictures/ImageToAnalyze.jpg
johnnie mac
  • 126
  • 1
  • 7