How to send multipart / form-data from Angular to Nodejs Multer?

From Angular I want to upload an image as Blob data to a nodeJS server. The server uses multer in the backend. The image file is created by processing the canvas. I am getting the following error from the server:

Error: Multipage: Border not found: 500

Below is my code. Please help me find out the problem.

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);

      

+3


source to share


1 answer


Remove the header 'Content-Type': 'multipart/form-data'

and it should work.

I got the same error, it is due to missing boundary=..

right after multipart/form-data

, as the following working query: enter image description here



When you remove your title, browsers will automatically add it with boundary=..

and it will work.

+4


source







All Articles