2

I'm hoping to find a solution for a frustrating problem in Meteor.js. I want to make some API calls to an open API service for face detection. I just need to send an image and receive a JSON object. I cannot find a way to send an image in the post body with meteor.js. The default http package in Meteor has the following method

HTTP.post(url, [callOptions], [asyncCallback])

or

HTTP.call(method, url, [options], [asyncCallback])

with the options

[options]  
 data Object
    JSON-able object to stringify and use as the HTTP request body. Overwrites content.

My question is how to attach a binary stream to the post body.

any help? Thanks

Ege Ugur
  • 21
  • 2
  • Have you tried simply writing the binary to a field in data? I haven't used the `HTTP` package, but I'd have to think it works the same as all posts. – CodeChimp May 11 '15 at 12:26

1 Answers1

2

I don't think you can do this with Meteor HTTP.call

if you look at their source code https://github.com/meteor/meteor/blob/devel/packages/http/httpcall_client.js You will find this

content = JSON.stringify(options.data);

To send binary data, you have to use XMLHttpRequest and FileReader API

I wrote an answer to a related topic at Meteor: uploading file from client to Mongo collection vs file system vs GridFS (using Option 2)

Community
  • 1
  • 1
Green
  • 4,950
  • 3
  • 27
  • 34