Asset file download to device
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?
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 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);
});
Can you try DocumentDirectoryPath instead of MainBundlePath?