joltup / rn-fetch-blob

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

Error on replacing file with same name, leads to deleted existing file #613

Open vinsensiussatya opened 4 years ago

vinsensiussatya commented 4 years ago

Library version : 0.10.15 RN version : 0.58.4 Device : iPhone 5S with iOS 12.4


Steps to reproduce :

  1. Have an existing file in a folder with a same name, for example someDocument.pdf
  2. Download a file with a same name to that folder.
  3. A popup will appear with the options to Replace or Keep Both files.
  4. Selecting Replace will delete the existing file but will not replace it with a new file because it says the file doesn't exist.

image

This is my code

const filename = "someDocument.pdf"
const docPath = `${RNFetchBlob.fs.dirs.DocumentDir}/${filename}`
const url = "http://some.website.com/downloadfile"

RNFetchBlob
.config({
    fileCache: true
    path: docPath
})
.fetch('GET', encodeURI(url), {})
.then((res) => {
    this.setState({submitted: false})
    RNFetchBlob.ios.previewDocument("file://" + docPath);
})

Thank you for the assistance