Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

146
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda