6

I'm trying simple code to copy a file to another external folder using this code:

RNFS.copyFile(sourcePath, destinationPath)
.then(result => {
  console.log('file copied:', result);
})
.catch(err => {
  console.log('error: ', err.message, err.code);
});

and i have already granted Android.Permission for read and write in external directory but it's still returning this error:

error:  EISDIR: illegal operation on a directory, read '/storage/emulated/0/' EISDIR

here are the dependency:

"react": "16.9.0",
"react-native": "0.61.2",
"react-native-fs": "^2.15.2"

BTW Am i request correct permission ?

PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE 
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE

Thanks for help in advance

2 Answers 2

8

I have resolved this issue, It was silly mistake. I forgot to mention name of the file in destination path url:

let sourcePath = "/storage/emulated/0/SourceFolder";
let destinationPath = "/storage/emulated/0/DestinationFolder";
let FileName = 'abc.jpg';

destinationPath = destinationPath +"/"+ FileName;

  RNFS.copyFile(sourcePath, destinationPath)  
    .then(result => {  
      console.log('file copied:', result);
    })
    .catch(err => {
      console.log(err);
    });
Sign up to request clarification or add additional context in comments.

Comments

0

Try this it works for me.

import {view, StyleSheet, PermissionsAndroid} from from 'react-native';

PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE);
    PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);

1 Comment

Permissions were already taken as mentioned by OP. Moreover, this porblem was solved here: stackoverflow.com/a/58554057/14291243

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.