Tuesday 9 May 2017

How to post multipart/form-data in angular2?

From Angular2 I want to upload a image Blob data to nodejs server. Server uses multer in backend. Image file is generating by canvas render. I am getting Error: Multipart: Boundary not found status:500 Error from server. Following is my code, please help me to find out the issue.

Angular2

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



via PARAMANANDA PRADHAN

No comments:

Post a Comment