0

I'm developing an application that runs both web and mobile app (React Native). In the mobile app, I have to fetch a file from S3 Bucket and convert it to base64 in order to show and write it to mobile storage.

When fetching a file that has a small size, I just fetch a file from S3 without responseType.

But when I fetch a large file, I don't get any data from API and the mobile app is stunned (it keeps loading and I cannot get any response from API). So I have to pass responseType: 'blob' to get data from API.

My question is: How to convert or read Blob to base64 while React Native cannot use FileReader like a web application?

Thanks in advance!

Rino
  • 53
  • 7
  • potentially [this](https://www.npmjs.com/package/react-native-base64)? – White Wizard Jan 03 '23 at 07:39
  • No, I don't know how to read blob to text on React Native, on web I use FileReader to read Blob as text then encode the text to base64 – Rino Jan 03 '23 at 07:46
  • Does this answer your question? [create react native app AWS S3 getObject use file](https://stackoverflow.com/questions/46222905/create-react-native-app-aws-s3-getobject-use-file) – White Wizard Jan 03 '23 at 07:51
  • thanks but in this question, the responseType is arrayBuffer. In my case, the response type is 'blob'. I try to fetch data as arrayBuffer but the API doesn't give me the response because the file that I fetch has large size – Rino Jan 03 '23 at 08:01

1 Answers1

0

Oh I try using FileReader to read Blob and it work! I thought FileReader is not working in React Native

Rino
  • 53
  • 7