简体   繁体   中英

How to send multipart/form-data file?

I have this in html:

Choose File
 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM