Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set reponseType as blob for $http in AngularJs?

Tags:

angularjs

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);
like image 696
anfas Avatar asked Sep 11 '14 11:09

anfas


People also ask

What happens when the responsetype is set to blob?

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.

How do I make an HTTP request in angular?

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.

How to display an image/jpeg REST API response using angular?

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.

What is @angular httpclient?

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.


Video Answer


1 Answers

angular provides config object for that , check docs

  $http({
        url: "http://localhost:8080/example/teste",
        method: "POST",
        responseType: "blob"

    })
like image 198
Narek Mamikonyan Avatar answered Oct 17 '22 01:10

Narek Mamikonyan