node.js 中的 cURL 请求
cURL request in node.js
谁能帮我弄清楚如何转换以下请求:
curl -F media=@image.jpg <url>
最好是 axios 请求。
您是否正在寻找这样的东西:
axios.put(url, imageFile, {
headers: {
'Content-Type': imageFile.type
});
.then(function(response) {
//Handle success.
});
.catch(function (error) {
//Handle errors.
});
我最终使用了 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);
谁能帮我弄清楚如何转换以下请求:
curl -F media=@image.jpg <url>
最好是 axios 请求。
您是否正在寻找这样的东西:
axios.put(url, imageFile, {
headers: {
'Content-Type': imageFile.type
});
.then(function(response) {
//Handle success.
});
.catch(function (error) {
//Handle errors.
});
我最终使用了 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);