Avoid using the FileReader API and instead, directly stream the file
object for better efficiency.
var config = { headers: { 'Content-Type': undefined } };
$http.post(url, file, config)
.then(function (response) {
var data = response.data;
var status = response.status;
var statusText = response.statusText;
var headers = response.headers;
var config = response.config;
console.log("Success");
return response;
}).catch(function (errorResponse)
console.log("Error");
throw errorResponse;
});
The XHR Send Method is capable of streaming file
objects as they are a type of Blob, eliminating the need to load the entire file into memory.
It is crucial to set the content type header to undefined
so that the XHR send method can properly handle it. Otherwise, AngularJS will default to application/json
.
Refer to AngularJS $http Service API Reference for more details.