запрос cURL в node.js - PullRequest
       13

запрос cURL в node.js

0 голосов
/ 03 сентября 2018

Может кто-нибудь помочь мне разобраться, как преобразовать следующий запрос:

curl -F media=@image.jpg <url>

предпочтительно на запрос axios.

Ответы [ 2 ]

0 голосов
/ 07 сентября 2018

Я использовал child_process

Вот пример кода:

const childProcess = require('child_process');
[...]

const output = childProcess
    //filePath is "image.jpg"; url is the link where the image will be uploaded
    .execSync(`curl -F media=@${filePath} "${url}"`)
    .toString('utf8');

const response = JSON.parse(output);
0 голосов
/ 03 сентября 2018

Вы ищете что-то вроде этого:

axios.put(url, imageFile, {
headers: {
'Content-Type': imageFile.type
});
  .then(function(response) {
   //Handle success.
});
  .catch(function (error) {
   //Handle errors.
});
...