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

Wrong filename provides to downloaded file if URI has no filename at the end. #567

Open paulrevival opened 4 years ago

paulrevival commented 4 years ago

If file's URI has no filename and(or) extension at the end (e.g. https://.../api/reference/financial, or https://.../api/files/ddf57hghm54s64s...), the downloaded file won't be saved properly. It won't have a real filename, but smth like "downloadfile.bin" on android and last part of save-dir on IOS (e.g save-dir === "/app/files" -> filename === "files").

That seems I have to set save-dir with a real filename at the end ("app/files/filename.ext"). But how can I do this if I didn't fetch the file yet?! :( If the URI-to-file includes a filename, file saves correctly on android, but still not (like described above) on IOS..

I just don't know how to resolve this.. :(

My code:

const fileURI = `https://.../files/sasf6s7dbd8fg90fdbetn`;
const saveToPath = `${dwnldFileDirs.DownloadDir}/app/files`;

RNFetchBlob
  .config({
    path: saveToPath,
    fileCache: true,
    addAndroidDownloads : {
      useDownloadManager : true,
      notification : true,
      mediaScannable: true,
      description : '',
      mime: '/'
    }
  })
  .fetch('GET', fileURI)
  .then((res) => {...})
davidgarra commented 3 years ago

did you find a solution?