i need to set response Type as 'blob' in angular. how to set response Type for $http in angularjs? sample code for set responseType using XMLHttpRequest is provided below. i need to replace XMLHttpRequest with $http.
var oMyForm = new FormData();
oMyForm.append("js", content);
var oReq = new XMLHttpRequest({mozSystem: true});
oReq.open("POST", url, true);
oReq.responseType = "blob";
oReq.onload = function(xhr) {
};
oReq.onerror = function(xhr) {
};
oReq.send(oMyForm);
The main answer first when the responseType is set the return type of the response is changed to Blob. To solve this add observe: 'response' which returns HTTPResponse. Example: I stumbled upon this issue and spent 6 hours solving.
Modern browsers support two different APIs for making HTTP requests: the XMLHttpRequest interface and the fetch () API. The HttpClient in @angular/common/ http offers a simplified client HTTP API for Angular applications that rests on the XMLHttpRequest interface exposed by browsers.
Using Angular's HttpClient "blob" response type to display an image. You can download the source code and follow along or fork the repository on GitHub: Next, run the gulp tasks, and then start the Node.js Express server. Create a simple Express Node.js HTTP server. Mock an image/jpeg REST API response.
Angular provides a client HTTP API for Angular applications, the HttpClient service class in @angular/common/ http. The HTTP client service offers the following major features. The ability to request typed response objects.
angular provides config object for that , check docs
$http({
url: "http://localhost:8080/example/teste",
method: "POST",
responseType: "blob"
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With