ammarahm-ed / react-native-scoped-storage

MIT License
58 stars 10 forks source link

How to copy image file from one folder to another? #40

Open ghulamabbas2 opened 1 year ago

ghulamabbas2 commented 1 year ago

I have written this code:

ScopedStorage.copyFile(item.uri, dir.uri)
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      });

The app crashes when I click on the button to copy the file. Can anyone provide me the correct way to copy file?

ammarahm-ed commented 1 year ago

@ghulamabbas2 First create the file you want to copy using ScopedStorage.createFile then use the returned url in copyfile to write it's contents.

const file = await ScopedStorage.createFile(...);
ScopedStorage.copyFile(item.uri, file.uri)
      .then(res => {
        console.log(res);
      })
      .catch(err => {
        console.log(err);
      });