I user 'react-native-fs' and 'react-native-fetch-blob' to test file download in android emulator, the console show me that the download is success, but I can not find where the file is in my emulator file system,or maybe it did not download successfully,can anybody tell me what to do,thanks
Asked
Active
Viewed 4,071 times
1
-
Which directory did you specify for download? – naomi Oct 23 '17 at 04:42
1 Answers
0
Use this function for Android with react-native-fetch-blob
.
It works for me and the downloaded file will be placed in the downloads directory of the device/emulator.
function downloadFile(url,fileName) {
const { config, fs } = RNFetchBlob;
const downloads = fs.dirs.DownloadDir;
return config({
// add this option that makes response data to be stored as a file,
// this is much more performant.
fileCache : true,
addAndroidDownloads : {
useDownloadManager : true,
notification : false,
path: downloads + '/' + fileName + '.pdf',
}
})
.fetch('GET', url);
}

David Schumann
- 13,380
- 9
- 75
- 96

naomi
- 2,583
- 2
- 22
- 39
-
Thanks for you answer,the code is useful,if you do not mind, I want to ask some question more,if I just know that it is a file but do not know what the document type is that i going to download,what should i do to advance the code, and do you have code about download in ISO,I am not good at Englisth,hope you can understand what i said,THANKS!THANKS!THANKS! – 蓝眼胡子 Oct 23 '17 at 06:06
-
1First, the file type may be part of the download url. Second, I haven't tried iOS, but I think the code should be pretty much the same. Except for `DownloadDir` is only supported for Android, so you should use `DocumentDir` instead, but then the file will be placed in the app's directory. At least, If the answer was helpful - You could up-vote it and mark as accepted. – naomi Oct 23 '17 at 06:24
-
-
notification false does not work for me, still shows notification when file download finished. Do you know why? – P.Lorand Mar 14 '18 at 13:34