Search code examples
angularangular-httpclient

Getting Blob object after posting data


I am posting some to data a rest api and should be getting a blob object as response. I need to download that blob or I would need to mail that in my angular application. But I am trying to figure out how to capture the blob object in response. My dataservice file is :

export class DataService<Type> {
private resolveSuffix: string = '?resolve=true';
private actionUrl: string;
private headers: Headers;

constructor(private http: Http, private httpClient:HttpClient) {    }
public issueId(asset: Type): Observable<Blob> {
    return this.httpC.post('http://localhost:3001/api/system/identities/issue', asset, {responseType: "blob"})
    .toPromise();
}

I am getting error :

property httpC doesn't exist on type 'DataService<Type>'

EDIT : first error fixed, now the error is Type 'Promise' is not assignable to type 'Observable'


Solution

  • now the error is Type 'Promise' is not assignable to type 'Observable'

    The error seems pretty clear. If you look at the documentation for httpClient methods, you can see that they return Observable.

    The return value of your service is Observable

    All you should need is to remove the toPromise() from your return statement.