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).
Oh, I found the problem.
No need to add "file://"in the RNFetchBlob path, and add "file://" when load files.
Most helpful comment
Oh, I found the problem.
No need to add "file://"in the RNFetchBlob path, and add "file://" when load files.