Tuesday 16 May 2017

Getting the file type in nodeJS and send it via http

I want to send the following request to some external API:

curl "https://api.foo.com/v2/" \
  -u USERNAME_OR_ACCESS_TOKEN \
  -X POST \
  -F file=@/path/to/my/file.json

But I want to do this with node. The file parameter is supposed to be a file - how can I do this from the node level? How can I send the file like here in cURL?

I've been trying to provide a string to the file relative to the node binary location, but of course it doesn't work:

this.api.sendRequest("https://api.foo.com/v2/", "POST", {
  file: "path/to/my/file.json"
});



via user99999

No comments:

Post a Comment