Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asset file download to device #1204

Open
Shivani12345 opened this issue Oct 4, 2023 · 3 comments
Open

Asset file download to device #1204

Shivani12345 opened this issue Oct 4, 2023 · 3 comments

Comments

@Shivani12345
Copy link

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?

@VMBindraban
Copy link

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)

@Shivani12345
Copy link
Author

@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);
});

@VMBindraban
Copy link

Can you try DocumentDirectoryPath instead of MainBundlePath?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants