RNFetchBlob无法正确下载(创建0个B文件)

时间:2018-10-14 11:26:55

标签: android reactjs react-native react-native-fetch-blob

我正在使用RNFetchBlob下载一些图片并将其保存在下载目录中。当我按下下载按钮时,它表示下载已完成,但是我的下载目录中只有一个长度为0字节的图像文件,显然无法打开!

这是我的代码:

downLoadFile() {
        const Url = 'https://www.shareicon.net/data/128x128/2017/06/05/886719_photo_512x512.png';

        let fileDirs = RNFetchBlob.fs.dirs.PictureDir;
        const filePathEnd = constants.download_image_path +
            Url.substring(Url.lastIndexOf("/") + 1, Url.lastIndexOf(".")+'.png');

        RNFetchBlob.config({
            fileCache: true,
            path: fileDirs + filePathEnd,
            addAndroidDownloads: {
                notification: true,
                title: "Download Successful",
                description: "An image file.",
                mediaScannable: true
            }
        })
            .fetch("GET", Url, {
                Authorization: "Bearer access-token..."
            })
            .then(res => {
                if (res.contentLength === res.bytesWritten) {
                    console.log("RNFetchBlob.config ok");
                }
            })
            .catch((errorMessage) => {
                console.log(" RNFetchBlob.config error", errorMessage);
            });
    }

我在控制台上得到“ RNFetchBlob.config ok”,似乎没有发生错误:|

OS:安卓

本机:55.4

react-native-fetch-blob:0.10.8

我在这里呆了2天。如果有人可以帮助我,请感谢:)

0 个答案:

没有答案
相关问题