React-native-fs: Can't use the downloadFile

Created on 3 Aug 2018  路  7Comments  路  Source: itinance/react-native-fs

Hello! I'm facing a difficult in use the lib. I'm trying to use the downloadFile and not return any errors and isn't working. This is my code:

RNFS.downloadFile({
  fromUrl: 'https://facebook.github.io/react-native/img/header_logo.png',
  toFile: `${RNFS.DocumentDirectoryPath}/react-native.png`,

}).promise.then((res) => {

  RNFS.exists('react-native.png').then((exists) => {

    console.log('exists');

  });
}).catch(() => {
  return Promise.reject(e);
});

Someone to help me please.

Most helpful comment

I have the same issue, download file on android does nothing but works correct on IOS.

download = async (target, destination) => {
        try{
            let options = {
                fromUrl: target,
                toFile: destination,
                begin: (res) => {
                    console.log(res)
                },
                progress: (data) => {
                    console.log(data)
                },
                background: true,
                progressDivider: 1
            }
            console.log(options)
            const request = await RNFS.downloadFile(options).promise
            console.log(request)
        }catch(e){
            console.log(e)
        }
    }

I only get 1 console log which is options before the await, it does not time out or error.

All 7 comments

I have the same issue, download file on android does nothing but works correct on IOS.

download = async (target, destination) => {
        try{
            let options = {
                fromUrl: target,
                toFile: destination,
                begin: (res) => {
                    console.log(res)
                },
                progress: (data) => {
                    console.log(data)
                },
                background: true,
                progressDivider: 1
            }
            console.log(options)
            const request = await RNFS.downloadFile(options).promise
            console.log(request)
        }catch(e){
            console.log(e)
        }
    }

I only get 1 console log which is options before the await, it does not time out or error.

I upgraded to react-native-fs 2.10.14 and it fixed it

Upgrading did not resolve this issue for me, happens only on Android devices.

I worked on version 2.9.12 in Android an IOS.

I suspect this line. Following this issue I replaced the line with downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); and it started working, but I don't know if it's correct approach here.

I suspect this line. Following this issue I replaced the line with downloader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); and it started working, but I don't know if it's correct approach here.

This is working too for me on Android 7 emulator and react native 0.57.8

Funny, it was working for me without at first but then it stopped. This also fixed it for me.

Was this page helpful?
0 / 5 - 0 ratings