Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

139
Views
How to download pdf file from local app storage to phone storage in react native using expo

I am looking for a way to download binary pdf file, which I get through api. I have this file in local app file system, but I would like to download it on my phone.

   const pdf = Buffer.from(res.data, "binary").toString("base64");
        const fileUri =
        FileSystem.documentDirectory + `${encodeURI("generated")}.pdf`;
        FileSystem.writeAsStringAsync(fileUri, pdf, {
          encoding: FileSystem.EncodingType.Base64
        }).then((respond) => {
          downloadPdf(fileUri);
          //Sharing.shareAsync(fileUri); // Here I can share file by other apps
        });


     const downloadPdf = async (uri) => {
     //Linking.openURL(uri)  // #approach 1

    //   MediaLibrary.saveToLibraryAsync(uri).then(res => {   // #approach 2
    //   console.log(res)
    // }).catch(err => {
    //   console.log(err)
    // })

   const permissions = await MediaLibrary.getPermissionsAsync(); 
    try {
      const asset = await MediaLibrary.createAssetAsync(uri);   // #approach 3

      const album = await MediaLibrary.getAlbumAsync("Downloads");
      if (album == null) {
        await MediaLibrary.createAlbumAsync("Downloads", asset, false);
      } else {
        await MediaLibrary.addAssetsToAlbumAsync([asset], album, false);
      }
    } catch (e) {
      console.log(e)
    }
};

I have tried different ways to do it, but I've stopped here with expo-media-library, which gives me:

"Unable to copy file into external storage" error.

Is it a good direction to use it ? Maybe you have some better solutions?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!