itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.9k stars 961 forks source link

Can't move image file to directory #431

Closed Tsiniloiv closed 6 years ago

Tsiniloiv commented 6 years ago

So I'm trying to use react-native-camera and react-native-fs together to take pictures and then save them to a folder I choose. I've managed to make the folder, but when I try to RNFS.moveFile it throws a weird yellowbox error:

C:[[path removed]]\node_modules\react-native\Libraries\ReactNative\YellowBox.js:82 Possible Unhandled Promise Rejection (id: 0):
Error: ENOENT: no such file or directory, open '[object Object]'
Error: ENOENT: no such file or directory, open '[object Object]'
    at createErrorFromErrorData (blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5:2016:17)
    at blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5:1968:27
    at MessageQueue.__invokeCallback (blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5:2410:18)
    at blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5:2155:18
    at MessageQueue.__guardSafe (blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5:2323:11)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5:2154:14)
    at http://localhost:8081/debugger-ui/debuggerWorker.js:72:58

If I try to examine the error further it catches another exception in the blob constructor at Blob.js:98, saying that 'parts' is undefined.

The idea is that react-native-camera saves the picture to a temporary folder, and then I use react-native-fs to move it to where I want it to be.

I can confirm that the picture gets taken, and react-native-fs seems to be working in general since I can do mkdir to make the target directory, but manually examining the directory finds it totally empty. The image does not get moved. What am I doing wrong?

  takePicture = () => {
    var directory = RNFS.ExternalStorageDirectoryPath + '/Pictures/KulaScope/Raw';
    RNFS.mkdir(directory.toString()).then( console.log(directory) );
    const options = {};
    if(this.camera) {
        this.camera.capture({metadata: options})
          .then(
            function(data) {
              console.log(data);
              return RNFS.moveFile(data.toString(), (directory + '/1.jpg').toString());
            })
          .catch(
            (err) => {
              console.log('ERROR: ' + err);
              throw err;
            });
    }
  };
Tsiniloiv commented 6 years ago

Disregad. The image path was under data.path, not data.

fukemy commented 4 months ago

Hi, how can you make RNFS work with blob file like this: blob:http://localhost:8081/c7257d7b-8273-4870-82db-484cd82571e5. I tried many ways but not working, I just want to download this blob file