Search code examples
nativescriptnativescript-angular

Blob type not supported


I am using Nativescript 5 and Angulat 4, and I am trying to download an image using a get request using @angular/http

getImageFile(path){
        let headers = new Headers();
        headers.set("Content-Type", "image/jpeg");

        return this.http.get((encodeURI(this.serverUrl + path)),{method: RequestMethod.Get,
        responseType: ResponseContentType.Blob, headers: headers })
            .map(res =>  res);
}

But it returns

Error: Response type of 'blob' not supported.

So I remove responseType: ResponseContentType.Blob and it works.

But when trying to get the information

this.myGetService.getImageFile('api/imagen/')
        .subscribe(
            response =>{
                try{
                    var blob = new Blob([response.blob()], {type: 'image/jpeg'});
                }catch(err){
                    console.log("Super Error !!!!", err);
                }
            }, (error) => {
                console.log("Error Request: " + error);
            });

Now it throws an exception.

Super Error !!!! ReferenceError: Can't find variable: Blob

Solution

  • It's an open feature request to support Blob format with the HttpClient in {N} Angular.

    A workaround could be using the getFile method on the default Http module.