Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FormData how to get or set boundary in multipart/form-data - Angular

I have a mini app, where I have to post a form data to an endpoint from browser.

This is my post:

var formData = new FormData();
formData.append('blobImage', blob, 'imagem' + (new Date()).getTime());

return $http({
  method: 'POST',
  url: api + '/url',
  data: formData,
  headers: {'Content-Type': 'multipart/form-data'}
})

Boundaries seems to be added by formData to the parameter, however, I cannot get it to send in the header, how should I done?

like image 797
Pablo Avatar asked Oct 31 '16 22:10

Pablo


People also ask

How do you add boundaries to multipart form data?

The boundary is included to separate name/value pair in the multipart/form-data . The boundary parameter acts like a marker for each pair of name and value in the multipart/form-data. The boundary parameter is automatically added to the Content-Type in the http (Hyper Text Transfer Protocol) request header.

What is boundary in Content-Type multipart form data?

multipart/form-data contains boundary to separate name/value pairs. The boundary acts like a marker of each chunk of name/value pairs passed when a form gets submitted. The boundary is automatically added to a content-type of a request header.

How do you set boundaries in HTTP request?

The boundary is specified like this: Content-Type: multipart/form-data; boundary=AaB03x . So, without a proper content-type, you almost can't have true multipart/form-data.


1 Answers

Well, seems that the headers ContentType should be undefined, in order to add the correct boundaries

like image 153
Pablo Avatar answered Sep 17 '22 17:09

Pablo