How to POST image as form data using npm request?

I have a specific task: I need to upload an image from the source URL and upload it to another host via a POST request as multipart / form-data. I am trying to use the node.js query library but it never succeeds. The following code does not send anything to the request body.

request.post({
  url: uploadUrl, 
  formData: {
    photo: request(imageUri)
  }
}, function (err) {
  if (err) console.error(err.stack)
});

I tried publishing directly through the form data library, but it doesn't seem to work. How to solve this problem without creating temporary files?

+4
source share
2 answers

, imageUri . , form-data. .

0

, , , . , - ...

request.get(imageUri).pipe(request.post(uploadUri));

, .

0

Source: https://habr.com/ru/post/1662194/


All Articles