Rn-fetch-blob: RNFetchBlob.fs.mv error: source file at path {PATH} does not exists

Created on 7 Aug 2018  路  5Comments  路  Source: joltup/rn-fetch-blob

MAY BE A BUG

When I am trying to move file from one directory to another this error is shown in console:

await RNFetchBlob.fs.mv(this.state.sourcePath, FilePicturePath() + this.state.filename);
item.js:136 Error: mv error: source file at path `file:///storage/emulated/0/Pictures/TEMP/1533659324.png` does not exists
    at fs.js:256
    at MessageQueue.__invokeCallback (MessageQueue.js:398)
    at MessageQueue.js:137
    at MessageQueue.__guardSafe (MessageQueue.js:314)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:136)
    at debuggerWorker.js:70

but I am pretty shure file is exist, because when I run following code it prints true

let exists = await RNFetchBlob.fs.exists(this.state.sourcePath);
console.log(exists);

Most helpful comment

You are right @ihavenoface5, it was an issue of the file:// prefix.

Incorrect:

file:///storage/emulated/0/Pictures/TEMP/1533659324.png

Correct:

/storage/emulated/0/Pictures/TEMP/1533659324.png

All 5 comments

I assume you are working with Android and it looks like you are trying to move a file that exists on external storage. You will need the WRITE_EXTERNAL_STORAGE permission. You need to request for this permission if you haven't already at runtime.

See https://facebook.github.io/react-native/docs/permissionsandroid for how to request runtime permissions.

Thank you so much for your reply @ihavenoface5

I am requesting both perrrmissions read and write

const granted_write = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
            {
                'title': 'WRITE_EXTERNAL_STORAGE',
                'message': 'MESSAGE'
            }
        )

        const granted_read = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
            {
                'title': 'READ_EXTERNAL_STORAGE',
                'message': 'MESSAGE'
            }
        )

But the problem is same file exists but cannot copy or move another location.

Error: mv error: source file at path `file:///storage/emulated/0/Pictures/TEMP/1533659324.png` does not exists

Is there some another way to debug whats the problem is?

It looks like the mv function doesn't expect a file URI (i.e. file:///storage/emulated/0/Pictures/TEMP/1533659324.png), but instead expects a path (/storage/emulated/0/Pictures/TEMP/1533659324.png). Can you try doing the move without the file:// appended to the beginning?

You are right @ihavenoface5, it was an issue of the file:// prefix.

Incorrect:

file:///storage/emulated/0/Pictures/TEMP/1533659324.png

Correct:

/storage/emulated/0/Pictures/TEMP/1533659324.png

I'm just going to leave this here for people who may get stuck in the future:

If you have done file exists and removed file:// and it is still not working.

Make sure that your destination is an existing directory or it will be rejected.

Was this page helpful?
0 / 5 - 0 ratings