[英]How to post multipart/form-data from Angular to Nodejs Multer?
From Angular I want to upload a image as Blob data to nodeJS server.从 Angular 我想将图像作为 Blob 数据上传到 nodeJS 服务器。 The server uses multer in the backend.
服务器在后端使用multer 。 The image file is generated by canvas render.
图像文件由画布渲染生成。 I am getting the following error from the server:
我从服务器收到以下错误:
Error: Multipart: Boundary not found status:500
错误:多部分:未找到边界状态:500
The following is my code.以下是我的代码。 Please help me to find out the issue.
请帮我找出问题所在。
Angular:角度:
// blob:Blob; -> it has valid image data.
var formData: FormData = new FormData();
formData.append('banner', blob, "my-file.png")
this.http.post(url,
formData, { headers: new Headers({ 'Content-Type': 'multipart/form-data' }) })
.toPromise()
.then(res => {
console.log(res);
return res.json();
})
.catch(this.handleError);
nodejs:节点:
router.post('/upload-banner-image', bannerImageUpload.single('banner'), watchfaceController.uploadWatchfaceBannerImage);
Remove your 'Content-Type': 'multipart/form-data'
header and it should work.删除您的
'Content-Type': 'multipart/form-data'
标题,它应该可以工作。
I got the same error, this is due to the missing boundary=..
just after multipart/form-data
like the following working request:我遇到了同样的错误,这是由于缺少
boundary=..
就在multipart/form-data
如下面的工作请求:
When you remove your header, browsers will add it automatically with the boundary=..
and it works.当您删除标题时,浏览器会自动添加
boundary=..
并且它可以工作。
添加 Content-Type': 'file' 在标题中,它应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.