Download flie which is in applications'asset folder to device with react-native

68 Views Asked by At

I need to download sample file to my iOS/Android device which is placed in application's assets folder with react native. I have implemented below code.

const assetPath = 'assets/icons/bootsplash.png';
    const destinationPath = `${RNFS.DocumentDirectoryPath}/bootsplash.png`;
    RNFS.copyFile(assetPath, destinationPath)
      .then(assetData => {
        console.log('assetDataassetData:', assetData);
      })
      .then(() => {
        console.log('Asset copied successfully to:', destinationPath);
      })
      .catch(error => {
        console.error('Error copying asset:', error);
      });

But showing error like

Error copying asset: [Error: The file “bootsplash.png” couldn’t be opened because there is no such file.]

1

There are 1 best solutions below

0
Vladlen Kaveev On

Try change destinationPath to:

const destinationPath = RNFS.DocumentDirectoryPath + 'bootsplash.png';

Also try to use copyFileAssets method on Android like this:

RNFS.copyFileAssets('assets/icons/bootsplash.png', RNFS.DocumentDirectoryPath + 'bootsplash.png').then((result) => console.log(result)).catch((error) => console.log(error));

If everything above not working, сheck the correctness of assetPath.