I am pretty new to Web Dev, and Meteor, and all things REST, but I am trying to write a server side method to make a Meteor http post request to a third party server, and upload an image to it. I am having trouble setting it up correctly. I want to upload a file in the body of a multipart/form-data section, but I am having trouble generating the correct request...
This is what i have:
Meteor.methods({
postOCR:function(newFile){
var options = {
headers: {'secret': mySecret,
'Content-Type': 'multipart/form-data'},
data: {'Content-Disposition': 'form-data',
'name':'image',
'filename':newFile
}
}
HTTP.call('POST', url, options, function(error, result) {
if (error) {
console.log('ERRR');
console.log(error);
} else
console.log('RESULT');
console.log(result);
});
}
});
And this is the request I am trying to build:
POST /some/res HTTP/1.1
Host: myUrl
secret: mySecret
Cache-Control: no-cache
----WebKitFormBoundaryE19zNvXGzXaLvS5C
Content-Disposition: form-data; name="multipart/form-data"; filename="img.jpg"
Content-Type: image/jpeg
----WebKitFormBoundaryE19zNvXGzXaLvS5C
The initial request is going through fine, but I don't seem to be uploading the file correctly...Can anyone tell me what I am doing wrong?
Thanks!