react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

Asset file download to device

Open Shivani12345 opened this issue 2 years ago • 3 comments

I need to download file which is in application to iOS device. which is located like

- appfolder 
   -src
      -assets
          -icons
              -bootsplash.png

I implemented code like below but the source path is not found by copyFile() function

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

When I try sourcepath with 'Users/m*****/Documents/reactProjs/MyApplication/src/assets/icons/bootsplash.png' its working but I want to set this path dynamically. How can we get application path dynamically with code or any other solution?

Shivani12345 avatar Oct 04 '23 12:10 Shivani12345

The sourcepath is not correct, it must be an absolute path. See constants.

It should be something like: ${RNFS.MainBundlePath}/src/assets/icons/bootsplash.png (depends on the OS)

VMBindraban avatar Oct 13 '23 10:10 VMBindraban

@VMBindraban I have put the same path and the path like

/Users/SAN***/Library/Developer/CoreSimulator/Devices/6FBB8EF2-3F3E-4E17-9525-1A051ETYTRU/data/Containers/Bundle/Application/B24AF1CD-480B-4374-B494-CD5240WSD123/BaseCodeStructure.app/src/assets/icons/bootsplash.png

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

MY CODE is

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

Shivani12345 avatar Oct 25 '23 06:10 Shivani12345

Can you try DocumentDirectoryPath instead of MainBundlePath?

VMBindraban avatar Oct 25 '23 08:10 VMBindraban