我只想让我的应用程序使用react-native-fetch-blob从服务器下载一个文件。问题是,文件存储在哪里?我只是从console.log -native-fetch-blob获取回调,并获得了这个对象
React-native-fetch-blob object callback
这是我的代码
alert("downloading");
RNFetchBlob
.config({
useDownloadManager : true,
fileCache : true
})
.fetch('GET', 'http://fontawesome.io/assets/font-awesome-4.7.0.zip', {})
.then((res) => {
console.log(res);
alert("Download");
alert('The file saved to ', res.path());
})有什么解决方案吗?
发布于 2019-06-08 13:05:26
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);
}
使用这个答案它肯定会起作用
发布于 2018-12-09 04:45:15
要使用rn-fetch-blob直接下载文件,需要将fileCache设置为true。
顺便说一句,不再维护react-native-fetch-blob,请改用rn-fetch-blob
document of download file directly
RNFetchBlob
.config({
// add this option that makes response data to be stored as a file,
// this is much more performant.
fileCache : true,
})
.fetch('GET', 'http://www.example.com/file/example.zip', {
//some headers ..
})
.then((res) => {
// the temp file path
console.log('The file saved to ', res.path())
})发布于 2017-06-20 20:58:54
我正在使用它,它工作得很好。你只需要像这样得到路径。
var filePath = res.path();这是您的文件存储的位置。
https://stackoverflow.com/questions/44652935
复制相似问题