react-native-fs icon indicating copy to clipboard operation
react-native-fs copied to clipboard

downloadFile example for v2.x

Open davidperrenoud opened this issue 10 years ago • 8 comments

This example worked in v1.5.1, but seems to have broken since v2.0.0:

RNFS.downloadFile(url, path).then(res => {
  this.setState({ downloaded: true });
});

Could you add a working example of downloadFile usage in the README?

davidperrenoud avatar Oct 05 '16 12:10 davidperrenoud

RNFS.downloadFile(url, path).promise.then(res => {
  this.setState({ downloaded: true });
});

The document here is clear

stillward avatar Oct 06 '16 06:10 stillward

As per the document,

RNFS.downloadFile(url, path).promise.then(res => {
  this.setState({ downloaded: true });
});

seems to be invalid, the following one works as of today.

RNFS.downloadFile({fromUrl:url, toFile: path}).promise.then(res => {
  this.setState({ downloaded: true });
});

Thank you @kiliwalk

palaniraja avatar Feb 03 '17 17:02 palaniraja

Thank you so much.Now it's working !!

ArwaLh avatar Mar 06 '17 09:03 ArwaLh

Hi I'm having this error

Error: ENOENT: no such file or directory, open '/data/user/0/com.kwanzaonline.toqueplay/files/download'
    at createErrorFromErrorData (D:\dev\mobile\toqueplay\node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:146)
    at D:\dev\mobile\toqueplay\node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:95
    at MessageQueue.__invokeCallback (D:\dev\mobile\toqueplay\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:397)
    at D:\dev\mobile\toqueplay\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:127
    at MessageQueue.__guard (D:\dev\mobile\toqueplay\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:297)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (D:\dev\mobile\toqueplay\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:126)
    at debuggerWorker.js:72

Any help?

ithustle avatar Oct 12 '18 08:10 ithustle

it is working and downloading file but i dont see that file in the photo app

apoorv-1310 avatar Nov 09 '18 14:11 apoorv-1310

When you trigger this function, what's the default behavior per OS?

I'm expecting that when the user taps the download button, it will open a file browser to let the user choose the download location. So in the future the user can open the file from his phone from outside the app.

What will it actually do on iOS and on Android?

adnanhz avatar Jan 15 '19 12:01 adnanhz

ES6 style

const downloadFile = async () =>{ try{ const data = await RNFS.downloadFile(url, path).promise; if(data){ this.setState({ downloaded: true }); } }catch(error){ console.log('error', error) } }

azizijunaid-zz avatar Aug 23 '20 18:08 azizijunaid-zz

it is working and downloading file but i dont see that file in the photo app

I have the same problem, how did you resolved it?

mouhsnimohamed avatar Dec 24 '20 20:12 mouhsnimohamed