Amplify-js: How to do an API call for blob data

Created on 31 Dec 2018  路  6Comments  路  Source: aws-amplify/amplify-js

I need to get blob data, not JSON data, from my REST API. Essentially, I'm looking for the equivalent of using fetch and https://developer.mozilla.org/en-US/docs/Web/API/Body/blob. How can I do this with Amplify?

API feature-request

Most helpful comment

I have the same problem when use AWS Amplify API. I need passing responseType: 'blob'
Is there any tentative date by when this feature?

@elorzafe

All 6 comments

Hey @epicfaace,

Are you using Amazon API Gateway to manage your REST API?

@epicfaace you can change the headers of the request like this

const data = await API.get('myApi','/myPath/to/my/data', {
      headers: {
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
      }
    });

@jordanranz No, I am not.
@elorzafe , that doesn't work. What I need is the ability to set responseType (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType) to "blob", which would mean passing in {responseType: blob} when calling axios.

Essentially, I am working around this issue by using fetch for now like this:
fetch(url).then(e => e.blob());

Because it seems that AWS Amplify assumes that the data type is json by default.

I will mark this as feature-request. @epicfaace thanks for your feedback

I have the same problem when use AWS Amplify API. I need passing responseType: 'blob'
Is there any tentative date by when this feature?

I have the same problem when use AWS Amplify API. I need passing responseType: 'blob'
Is there any tentative date by when this feature?

@elorzafe

Was this page helpful?
0 / 5 - 0 ratings