joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.84k stars 784 forks source link

File sometimes empty when using `fileCache: true` #48

Open nkov opened 6 years ago

nkov commented 6 years ago

We use the library to retrieve authenticated images like this:

import RNFetchBlob from 'react-native-fetch-blob'

RNFetchBlob
  .config({ fileCache: true })
  .fetch('GET', url, { Authorization: `Bearer ${token}` })
  .then(res => {
      console.log('path: ', res.path())
  })

Usually this works fine but sometimes the path which is returned leads to a 0 byte file instead of the actual file (for the same URL). I have confirmed on the local filesystem with the simulator but this seems to be happening on physical devices as well.

Using version 0.10.8 on React/RN 16.2/0.53

Traviskn commented 6 years ago

I've experienced this type of issue before as well. I believe that the fileCache is a location intended for temporary storage. This means the cached file location is ephemeral and could be cleared out by Android. You may need to store your file in a different path such as RNFetchBlob.fs.dirs.DocumentDir using the path key in the config object.https://github.com/wkh237/react-native-fetch-blob/wiki/Classes#pathstring-1

quenice commented 6 years ago

+1