#How can I fetch assets and images using axios?

8 messages · Page 1 of 1 (latest)

wintry kraken
#

Hi folks!

I am trying to fetch an image from the server through axios but I couldn't. I tried to add this to the request configs responseType: "blob" but it doesn't work too. I searched in the great docs but I could find a guide on the API response, unfortunately.

What is the proper way to achieve that on React Native?

quaint stone
#

Use /assets endpoint with the uuid of a file and responseType: 'blob' (and set authorization header if not public), save this to a variable, e.g. response. Then use URL.createObjectURL(response.data) to get a local blob url. It works this way in a browser, not sure if it has to be different with React Native.

wintry kraken
#

@quaint stone Thanks for the reply. It doesn't work with React Native, as I am getting this error: Error: Cannot create URL for blob!
Also, I tried to verify the type of the object I am receiving through axios, and it is not instanceof Blob

#

The data I am receiving looks like that:
{"__collector": {}, "blobId": "95f88daa-a5b2-4081-ae5d-6812016ff4b8", "offset": 0, "size": 7575}

quaint stone
#

Does it work when setting up a normal html/js site with axios? Just to exclude the possibility that there is some error in the request, axios configuration or even directus. I do not know how React Native works in detail, if it is like a browser environment or more like node, where specific browser functions do not exist.

wintry kraken
#

Yeah, I think the issue is in RN. It requires additional efforts to get and handle blobs

quaint stone
wintry kraken
#

Thanks for sharing that, @quaint stone! It turns out that is not possible at this moment to get pictures through axios on RN, which is really weird. The root issue is from RN itself.