#How can I fetch assets and images using axios?
8 messages · Page 1 of 1 (latest)
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.
@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}
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.
Yeah, I think the issue is in RN. It requires additional efforts to get and handle blobs
Could this help in any way? https://www.waldo.com/blog/react-native-fetch-blob
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.