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 770 forks source link

File download: Unable to locate file after download #212

Open viv3kk opened 5 years ago

viv3kk commented 5 years ago
RNFetchBlob
            .config({
              fileCache : true,
              // android only options, these options be a no-op on IOS

            })
            .fetch('GET', 'http://117.12.209.52/jdrr_cert_gen/images/image_283.jpg', {
              //some headers ..
            })
            .then((res) => {
              // the path should be dirs.DocumentDir + 'path-to-file.anything'
              console.log('The file saved to ', res.path())
            })

console.log('The file saved to ', res.path()) returns /data/user/0/com.myapp/files/RNFetchBlobTmp_x34fi32dgqgwbthcfrdc8e

I have also used download manager and specific path but unable to loacte file. When i am using download manager, I also get a notification but no image.

React native : 0.56 Mutliple Physical devices used

viv3kk commented 5 years ago

Respone when we use download manager

respInfo:
headers:
accept-ranges: "bytes"
cache-control: "public, max-age=31536000"
cf-cache-status: "HIT"
cf-ray: "46b1c2a30f1b8aaf-BOM"
content-length: "606640"
content-type: "image/jpeg"
date: "Wed, 17 Oct 2018 09:32:51 GMT"
expect-ct: "max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct""
expires: "Thu, 17 Oct 2019 09:32:51 GMT"
last-modified: "Fri, 05 Oct 2018 2:21:52 GMT"
server: "cloudflare"
set-cookie: "__cfduid=db7793343e709a7e22de59e602d00a6b21539768771; expires=Thu, 17-Oct-19 09:32:51 GMT; path=/; domain=.pexels.com; HttpOnly"
vary: "Accept-Encoding"
x-cache: "HIT, MISS"
x-content-type-options: "nosniff"
x-served-by: "cache-lax8625-LAX, cache-bom18225-BOM"
__proto__: Object
redirects: Array(1)
0: "https://images.pexels.com/photos/570987/pexels-photo-570987.jpeg"
length: 1
__proto__: Array(0)
respType: ""
rnfbEncode: "path"
state: "2"
status: 200
taskId: "tyaaued2h7826b0kfna1m"
timeout: false
Wind213 commented 5 years ago

I got the same problem did you solve this ?

Wind213 commented 5 years ago

in my case i change my dir from .config({ // response data will be saved to this path if it has access right. path : '/data/0/user/{packageName}/file/{imageName}.jpg' })

to .config({ // response data will be saved to this path if it has access right. path : '/storage/emulated/0/{appName}/{imageName}.jpg' })

and, it works.

Wind213 commented 5 years ago

if you have a better solution please tell me

viv3kk commented 5 years ago

no did not solve this... will try ur solution

KeithM23 commented 5 years ago

Make sure to check you have the write external storage permission for android, I left this out and everything appeared to work correctly accept file wouldn't show up

Fantasim commented 5 years ago

Got the same problem, how did you do to locate the file?

(I've actived the WRITE_EXTERNAL_STORAGE permission)

vitorverasm commented 5 years ago

I'm facing the same issue but only in iOS device using RNFetchBlob.fs.dirs.DocumentDir as path. The fetch response comes with the correct path but after download i got no file.

EDIT: i've solved this by using WRITE_EXTERNAL_STORAGE permission on Android. And using this keys in info.plist for iOS:

<key> UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

As described here, to enable file sharing in the app Document folder.

hisanibrahim commented 4 years ago

I was faced same issue, but it solved. Simple solution that worked was

  1. Open App Info from mobile
  2. In Permissions -> Please make sure Storage is ticked
rajeshde commented 4 years ago

I'm facing the same issue but only in iOS device using RNFetchBlob.fs.dirs.DocumentDir as path. The fetch response comes with the correct path but after download i got no file.

EDIT: i've solved this by using WRITE_EXTERNAL_STORAGE permission on Android. And using this keys in info.plist for iOS:

<key> UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

As described here, to enable file sharing in the app Document folder.

After downloading a pdf file using RNFetchBlob, I can see the document exists in RNFetchBlob.fs.dirs.DocumentDir. But, I can not see the file in files app in iOS. It's working fine for Android though.

vitorverasm commented 4 years ago

That happened to me... I solved by adding the fix mentioned above, but I also created a new folder inside RNFetchBlob.fs.dirs.DocumentDir to store my PDF files. Don't know if this will help you but you can try.

RaphaPetrere commented 4 years ago

@vitorverasm o comando WRITE_EXTERNAL_STORAGE eu colocaria aonde no projeto android? E tem diferença entre colocar ele e ativar manualmente o armazenamento?

vitorverasm commented 4 years ago

@RaphaPetrere vc tem q incluir essa permissão no arquivo android/app/src/main/AndroidManifest.xml :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

É importante colocar a definição do uso da permissão no manifest, ao fazer isso o app ja identifica que precisa dessa permissão e vc não tem que ativar manualmente.

deepaktringapps commented 2 years ago

I'm facing the same issue but only in iOS device using RNFetchBlob.fs.dirs.DocumentDir as path. The fetch response comes with the correct path but after download i got no file. EDIT: i've solved this by using WRITE_EXTERNAL_STORAGE permission on Android. And using this keys in info.plist for iOS:

<key> UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>

As described here, to enable file sharing in the app Document folder.

After downloading a pdf file using RNFetchBlob, I can see the document exists in RNFetchBlob.fs.dirs.DocumentDir. But, I can not see the file in files app in iOS. It's working fine for Android though.

I also facing same problem, By chance find any solution?

heytulsiprasad commented 2 years ago

I also facing same problem, By chance find any solution?

Try upgrading this package to latest. I had that issue while using DownloadsManager where I was using some previous version than latest.