I am working on sending an image (base64) via a POST request and waiting for the response. The POST request should have a Content-Type
of multipart/form-data
, and the image itself should be of type image/jpg
.
This is what the POST request should look like:
POST https://www.url... HTTP/1.1
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
User-Agent: Fiddler
Host: www.host.com
Content-Length: 199640
---------------------------acebdf13572468
Content-Disposition: form-data; name="fieldNameHere"; filename="Nikon Digital SLR Camera D3100 14.2MP 2.jpg"
Content-Type: image/jpeg
The actual binary image data will be the content body.
I'm trying to use the Http Post method in Angular 2, but I'm unsure about how to properly structure the request. Here is my current code snippet:
let body = atob(imageData);
let headers = new Headers({'Content-Type': 'multipart/form-data'});
let options = new RequestOptions({headers: headers});
this._http.post(url, body, options)
.map(res=>{
//do stuff
});
While this code appears to be missing some crucial parts, particularly regarding the Content-Disposition and Type of the binary image data, I am uncertain about how to proceed in order to include these details.