2

I used react-native-fetch-blob to download file excel from api. I can see it's downloading successfully but as you know On iOS platform the directory path will be changed every time you access to the file system.

I show the path by console.log:

"/Users/admin/Library/Developer/CoreSimulator/Devices/749E7AAA-F568-4F56-9606-FF23E84946CF/data/Containers/Bundle/Application/95C3997D-BBB3-4FB3-94C4-ADB0331940B2/Bus_Booking.app/MYFILE.xlsx".

But when I go to the folder of the device, there are no files to see. How can I download and write the path where a user can see their device?

Jessica Rodriguez
  • 2,899
  • 1
  • 12
  • 27

1 Answers1

0

You need to save file to a directory, else it will be saved in a temporary directory only available to app.

const baseDir = RNFetchBlob.fs.dirs.DownloadDir;
const path = `${baseDir}/my-file.png`;
RNFetchBlob.fs.writeFile(path, <temp file path>, 'uri');

react-native-fetch-blob repo is not maintained anymore. Use rn-fetch-blob

Fawaz
  • 3,404
  • 3
  • 17
  • 22
  • plz tell me what is temp file path, sorry for the noob question – Hồ Quốc Huy Oct 02 '18 at 09:06
  • DocumentDir CacheDir MainBundleDir (Can be used to access files embedded on iOS apps only) DCIMDir (Android Only) DownloadDir (Android Only) MusicDir (Android Only) PictureDir (Android Only) MovieDir (Android Only) RingtoneDir (Android Only) SDCardDir (0.9.5+ Android Only) – Hồ Quốc Huy Oct 03 '18 at 01:38
  • i want to save to iphone or ipad not android device – Hồ Quốc Huy Oct 03 '18 at 01:39
  • @HồQuốcHuy the path you mentioned in your question is the tmp path `/Users/admin/Library/Developer/CoreSimulator/Devices/749E7AAA-F568-4F56-9606-FF23E84946CF/data/Containers/Bundle/Application/95C3997D-BBB3-4FB3-94C4-ADB0331940B2/Bus_Booking.app/MYFILE.xlsx` – Fawaz Oct 03 '18 at 07:16
  • the path you write is a dynamic path. So i used react native FileViewer to open file and user can save it to their device. – Hồ Quốc Huy Oct 03 '18 at 07:39