[英]How to send multipart/form-data file?
I have this in html:我在 html 中有这个:
handleFileInput(files: FileList) { const headers = new Headers({ 'Content-Type': 'multipart/form-data' }); var formData = new FormData(); formData.append("myFile", files.item[0]); this.api.postWithoutEntity('/socialintegration/callback/attachment', { recipientId: this.selected.custSocId, file: formData }).subscribe(); this.upload = false; }
but im getting this: Current request is not a multipart request"但我得到了这个:当前请求不是多部分请求”
Any suggestion?有什么建议吗?
I don't know how your this.api.postWithoutEntity method works, but you aren't using headers variable.我不知道你的 this.api.postWithoutEntity 方法是如何工作的,但你没有使用 headers 变量。 You must pass your headers on request
您必须根据要求传递您的标头
const headers = new Headers({ 'Content-Type': 'multipart/form-data' });
return this.http.post<any>(
"/socialintegration/callback/attachment",
{recipientId: this.selected.custSocId, file: formData},
headers
);
https://angular.io/guide/http#updating-headers https://angular.io/guide/http#updating-headers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.