Save Blob to FileSystem

#1

I’m trying to save a PDF file that I download as a Blob to the FileSystem so I can open it with Linking.openURL(myLocalPdfRoute) but I am not being able to save the file.

This is the code I’m using for saving the file:

// response comes from the axios request
const file = new Blob(
        [response.data],
        { type: 'application/pdf' },
      );
const saved = FileSystem.writeAsStringAsync(`${FileSystem.documentDirectory}my.pdf`, file).then(() => {
        console.log('SAVED: ', saved);
        Linking.openURL(`${FileSystem.documentDirectory}my.pdf`).catch((error) => {
          console.log('ERROR: ', error);
        });
      })

It looks like I need to do something with the blob before trying to save it to the FS, but I don’t know what.

EDIT:
I don’t think that using FileSystem.downloadAsync could be an option since the authorization on the API

Any help will be appreciated.
Thanks.

1 Like
closed #2

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.