itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.94k stars 976 forks source link

Cannot use copyFileAssets to copy file from android assets folder #334

Open puzpuz opened 7 years ago

puzpuz commented 7 years ago

RN: 0.43.3 RNFS: 2.5.1

I am trying to copy file from android assets folder into android document directory path.

  1. I test the file's existence using RNFS.existsAssets('stickers/test.txt').then((result) => console.log(result));. The result is true
  2. I copy the textfile into DocumentDirectoryPath using RNFS.copyFileAssets('stickers/test.txt', RNFS.DocumentDirectoryPath) .then((result) => console.log(result)) .catch((error) => console.log(error));. It shows

{ [Error: ENOENT: no such file or directory, open 'stickers/test.txt'] framesToPop: 1, code: 'ENOENT' }

Expected behavior: Since existsAssets returned TRUE, the file should be copied successfully into new directory instead of returning file not found

SoundBlaster commented 7 years ago

You need to send full path with file name:

RNFS.copyFileAssets('stickers/test.txt', RNFS.DocumentDirectoryPath + 'test.txt') .then((result) => console.log(result)) .catch((error) => console.log(error));
aschenkel commented 6 years ago

Having same issue. @SoundBlaster clarification is correct but there is still an issue with the source path (that being android assets folder)

@puzpuz Have you found any workaround?

@benvium any idea what could be wrong?

puzpuz commented 6 years ago

Hi @aschenkel ...

In my project, since my asset's file is a zip folder, I am using another library (react-native-zip-archive) to unzip the file and put inside android's document directory file. This is not exactly a solution, but since my file is consist of a lot of images, zipping it would be the best solution for me :)

tragicmj commented 2 years ago

Facing same issue, I need to open a pdf file using external pdf opener [Error: Asset '/data/user/0/com.fleapo.jharkhandupdate/files/JharkhandUpdate/JharkhandUpdateDocuments/JharkhandUpdate1633700791252.pdf' could not be opened] This is the error that I am getting.

daryazata commented 2 years ago

Also getting this error

omarbakr2020 commented 1 year ago

Hey Guys, Any updates on this issue ?