React-native-fetch-blob: File not saved in Android

Created on 15 Sep 2017  路  1Comment  路  Source: wkh237/react-native-fetch-blob

React-native: 0.47.1
react-native-fetch-blob: 0.10.8

Hi, I'm trying to download and save the file to specify path
It's work in iOS but I got a problem in Android.

Seems like unable to save the file to specify path, but it's working when "fileCache : true"
Here is my code.

function getFilePath(group) {
    let dirs = RNFetchBlob.fs.dirs;

    var output_path = Platform.OS === 'android' ?
            ('file://' + dirs.DocumentDir+'/'+group) :
            dirs.DocumentDir+'/'+group;
    return output_path;
}


const filePath = Utils.getFilePath(mediaType)+'/'+filename+'.jpg';
RNFetchBlob.config({
    trusty : true,
    path: filePath
})
.fetch(
    'GET', 
    url, {
                //some headers ..
    })
.then((res) => {
    console.log(res.path());
    callback(res.path());
})
.catch((errorMessage, statusCode) => {
    console.log("Error: "+ errorMessage + " - " + statusCode);
})

The result of res.path() is "file:///data/data/com.pchat/files/AVATAR/59a648ce9b0fa407e2c84f02.jpg"
Seems like normal, but in the same time I go to "file:///data/data/com.pchat/files/" it's have 1 file only (ReactNativeDevBundle.js).

android

Most helpful comment

Oh, I found the problem.
No need to add "file://"in the RNFetchBlob path, and add "file://" when load files.

>All comments

Oh, I found the problem.
No need to add "file://"in the RNFetchBlob path, and add "file://" when load files.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gonglong picture gonglong  路  3Comments

yaronlevi picture yaronlevi  路  4Comments

nsethuraman picture nsethuraman  路  3Comments

jackdoe picture jackdoe  路  4Comments

nielsswinkels picture nielsswinkels  路  3Comments