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

Download file on iOS

Open hoangvuanhdevelopervn opened this issue 7 years ago • 3 comments

I use react-native-fs to download file in iOS. I check on simulator it's download success with path:

/Users/admin/Library/Developer/CoreSimulator/Devices/443C8F7F-AB92-4217-A999-A7BDBA52A6B6/data/Containers/Data/Application/99958A5C-E350-4855-B8CE-ED6FA999C619/Documents.

On real device, it's path (iPhone 8 Plus White 64Gb):

/var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg

I try set: const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;

but it't not work. I want to this image display on photo, this mean after download success i can see it on my photo immediately, how can do that and what about the others file like: mp3, mp4, text, after download, how to find it's and show for user when they want to read?

This is my code:

downloadFile1 = (url, name) => {
    const destPath = RNFS.DocumentDirectoryPath + '/images/' + name;
    let option = {
      fromUrl: url,
      toFile: destPath
    };
    RNFS.downloadFile(option).promise.then(res => {
      console.log('res -----------------------------> ', res);
    });
  };

hoangvuanhdevelopervn avatar Aug 27 '18 04:08 hoangvuanhdevelopervn

Had similar issue and I think I found the problem:

It's because you want to store the file in a dir images that doesn't exist yet. Either drop this from the destPath or make sure this dir exists before starting the download.

michaldudek avatar Sep 12 '18 15:09 michaldudek

Hey @hoangvuanhdevelopervn , Have you figured out a way to find the file and show for user when they want to read? Is there a way to navigate to this path : /var/mobile/Containers/Data/Application/63F84623-E684-456F-A55A-01E22708C012/Documents/pexels-photo-1109561.jpeg Thanks

AravindTReddy avatar Apr 02 '20 17:04 AravindTReddy

@hoangvuanhdevelopervn @AravindTReddy , ref to https://github.com/itinance/react-native-fs/issues/897#issuecomment-759577180 , thus I can let .gif file saved with my APP PixelShapeRN running on iOS be located on the device with my APP and other APP, for example iOS "File Explorer" app now can find the .gif file and show for user.

flyskywhy avatar Feb 25 '22 02:02 flyskywhy