react-native-background-downloader icon indicating copy to clipboard operation
react-native-background-downloader copied to clipboard

Not Able to download in Android device. Download canceled due to error: FILE_NOT_FOUND Download canceled due to error: UNKNOWN_IO_ERROR

Open kp72-dev opened this issue 4 years ago • 4 comments

My code

 startDownload(item) {
        var ext = this.getExtention(item.title);
        let nameId = item.name
        let urls = item.title
        ext = '.' + ext[0];
        let dirs = RNFetchBlob.fs.dirs.PictureDir
        let fileName = `GIFs__(( '${item.id}))__ ${new Date()} ${ext}`;
        console.log(urls.toString())
        let task = RNBackgroundDownloader.download({
            id: nameId.toString(),
            url: urls.toString(),
            destination: `${dirs}'/'${fileName}`
        }).begin((expectedBytes) => {

            console.log(dirs + fileName)

            let newResult = this.state.files

            newResult.filter((mainFile) => {
                if (mainFile == item) {
                    console.log(mainFile)
                    return mainFile
                }
            }).map((value) => value.is_downloading = true);

            this.setState({ files: newResult })

            console.log(`Going to download ${expectedBytes} bytes!` + item.id);

        }).progress((percent) => {

            console.log(`Downloaded: ${percent * 100}%`);

        }).done(() => {

            this.setState(prevState => ({
                files: prevState.files.filter(newitem => newitem.id !== item.id),
            }));

            console.log('Download is done!', item.id);

        }).error((error) => {
            console.log('Download canceled due to error: ', error);
        });
    }

OUTPUT::=> [Fri Nov 20 2020 12:23:56.700] LOG https://file-examples-com.github.io/uploads/2018/04/file_example_AVI_1280_1_5MG.avi [Fri Nov 20 2020 12:23:56.730] LOG Download canceled due to error: FILE_NOT_FOUND [Fri Nov 20 2020 12:24:11.746] LOG https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1920_18MG.mp4 [Fri Nov 20 2020 12:24:11.749] LOG Download canceled due to error: FILE_NOT_FOUND [Fri Nov 20 2020 12:24:14.468] LOG https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_640_3MG.mp4 [Fri Nov 20 2020 12:24:14.470] LOG Download canceled due to error: FILE_NOT_FOUND [Fri Nov 20 2020 12:24:15.400] LOG https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4 [Fri Nov 20 2020 12:24:15.430] LOG Download canceled due to error: FILE_NOT_FOUND [Fri Nov 20 2020 12:24:16.479] LOG https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_480_1_5MG.mp4 [Fri Nov 20 2020 12:24:16.515] LOG Download canceled due to error: FILE_NOT_FOUND [Fri Nov 20 2020 12:24:16.935] LOG https://file-examples-com.github.io/uploads/2017/04/file_example_MP4_1280_10MG.mp4 [Fri Nov 20 2020 12:24:16.937] LOG Download canceled due to error: FILE_NOT_FOUND

One more output=>

`[Fri Nov 20 2020 12:28:38.431] LOG Download canceled due to error: UNKNOWN_IO_ERROR [Fri Nov 20 2020 12:28:42.768] LOG Download canceled due to error: UNKNOWN_IO_ERROR [Fri Nov 20 2020 12:28:42.959] LOG Download canceled due to error: UNKNOWN_IO_ERROR [Fri Nov 20 2020 12:28:43.191] LOG Download canceled due to error: UNKNOWN_IO_ERROR [Fri Nov 20 2020 12:28:43.360] LOG Download canceled due to error: UNKNOWN_IO_ERROR

` here is its code. Screenshot 2020-11-20 at 12 27 57 PM minor changes. its working fine in iOS no issues at all.

kp72-dev avatar Nov 20 '20 07:11 kp72-dev

i am still facing this issue help needed. @ptelad

kp72-dev avatar Dec 01 '20 05:12 kp72-dev

Hey @kp72-dev, I've got this issue today. Was able to solve it by updating the AndroidManifest file to add this:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:requestLegacyExternalStorage="true" //Add this Line
    android:label="@string/app_name"
>

    ---------<Activity, Sevices or Recivers>----------

</application>

WNemencha avatar Feb 20 '21 21:02 WNemencha

Hi, I'm facing this issue too. on android 7 nox emulator everythings works fine but on a real android 11 device it keeps throwing UNKNOWN_IO_ERROR I set the android:requestLegacyExternalStorage="true" , checked my permissions and logged my url and destination path but its not working. Any idea about this?

Im using react native 0.63.3 if you need more information please do inform me.

armata99 avatar Jul 05 '21 11:07 armata99

as they mentioned here the fetch library has to be updated to become compatible with android 11. after that there might be some reviews needed for this library too.

armata99 avatar Jul 06 '21 05:07 armata99