1

I'm using RNFetchBlob to download some pictures and save them in the download directory. When I press the download button, it says the download finishes but there's just an image file with 0 bytes length in my download directory that obviously can not be opened!

Here is my code:

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);
            });
    }

I get 'RNFetchBlob.config ok' on console and no error seems to occur :|

OS : android

react-native : 55.4

react-native-fetch-blob: 0.10.8

I'm stuck in here for 2 days. Appreciate it if anyone could help me out :)

Zeynab Rostami
  • 423
  • 4
  • 13

0 Answers0