【发布时间】:2020-11-14 19:28:48
【问题描述】:
我正在尝试将视频发送到视频网站,我可以使用 REST api 和邮递员上传视频,所以我知道 api 可以按预期工作。现在我想使用 axios 做同样的请求。我的代码类似于如何使用表单数据和 axios 的示例:
const form = new FormData();
const stream = fs.createReadStream(PATH_TO_FILE);
form.append('image', stream);
// In Node.js environment you need to set boundary in the header field 'Content-Type' by calling method `getHeaders`
const formHeaders = form.getHeaders();
axios.post('http://example.com', form, {
headers: {
...formHeaders,
},
})
.then(response => response)
.catch(error => error)
我收到data: 'Content-Length is required'的错误
有什么想法吗?
【问题讨论】:
-
请不要在问题中写答案(作为单独的答案发布)。
标签: javascript node.js axios form-data