5

I try to download an image(png) from a api. My problem is, that for some reason only json files are accepted by ionic/angular.

return this.http.get(this.authKeys.serverURL, {headers: this.header, responseType: ResponseContentType.Blob});

Following error occurs:

 Argument of type '{ headers: any; responseType: ResponseContentType.Blob; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: Ht...'.   Types of property 'responseType' are incompatible.     Type 'ResponseContentType.Blob' is not assignable to type '"json"'.

For some reason only a response of type json is allowed...

1

2 Answers 2

11

responseType holds string value. So you should be passing either of these values

'arraybuffer' | 'blob' | 'json' | 'text';

In earlier version Angular 2, it API was designed to expect enum value for responseType, check here

Sign up to request clarification or add additional context in comments.

1 Comment

I'm also getting the same error even when I use one of those four Strings. Any suggestions?
7

For me, it worked with " as 'json' " syntax:

responseType: 'blob' as 'json'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.