Angular - upload file as base64
For sending big files to server you should use FormData
to be able to send it as multi-part instead of a single big file.
Something like:
// import {Http, RequestOptions} from '@angular/http';uploadFileToUrl(files, uploadUrl): Promise<any> { // Note that setting a content-type header // for mutlipart forms breaks some built in // request parsers like multer in express. const options = new RequestOptions(); const formData = new FormData(); // Append files to the virtual form. for (const file of files) { formData.append(file.name, file) } // Send it. return this.http.post(uploadUrl, formData, options); }
Also don't forget to set the header 'Content-Type': undefined
, I've scratched my head over this for hours.