Skip to content

Failed to find configured root that contains /data/data/com.android.providers.downloads/cache/filename.pdf #40

Closed

Description

@arunim2405

Failed to find configured root that contains /data/data/com.android.providers.downloads/cache/filename.pdf
This error occurs when I try to open a pdf I downloaded using
android.actionViewIntent(res.path(), 'application/pdf')
The file itself saves successfully to the path I presume, but I have no way to check
Also when is the ability to save to MediaStore.Download will come?
Any help would be appreciated, thanks!

Activity

  1. RonRadtke commented on Jun 19, 2021

    @RonRadtke
    Owner

    To which directory are you saving the file?
    Looks like it is outside of your apps private directories

  2. arunim2405 commented on Jul 3, 2021

    @arunim2405
    Author

    I was trying to download the file in the common downloads directory of android, but I changed that to my app directory and that fixed the issue. Is it or when will it be possible to directly download to the common downloads directory?

  3. RonRadtke commented on Jul 3, 2021

    @RonRadtke
    Owner

    It's currently not possible, no.
    I plan on implementing a possibility to write / read to / from the Media collections in august. With this change it then should be possible to store files in the common downloads directory too

  4. Kamani commented on Jul 8, 2021

    @Kamani

    @arunim2405 how you saved file to your app directory?

  5. arunim2405 commented on Jul 8, 2021

    @arunim2405
    Author

    @Kamani
    I was also using import RNFS from'react-native-fs';
    so in my path I just used
    path : RNFS.ExternalDirectoryPath +'/certificate.pdf',

  6. Kamani commented on Jul 13, 2021

    @Kamani

    @arunim2405
    I tried to save file directly as you mentioned path : RNFS.ExternalDirectoryPath +'/certificate.pdf',.

    `
    ReactNativeBlobUtil.config({

      path: RNFS.ExternalDirectoryPath + 'receipt.pdf',
    
      addAndroidDownloads: {
    
        useDownloadManager: true,
    
        notification: true,
    
        mime: 'application/pdf',
    
        description: 'Downloading Receipt.',
    
        mediaScannable: true,
    
      },
    
      overwrite: false,
    
    })`
    

    But it keeps saving file in /data/data/com.android.providers.downloads/cache/
    Any Idea?

  7. Kamani commented on Jul 13, 2021

    @Kamani

    @arunim2405 Infact I am also not able to copy file from this directory.
    /data/data/com.android.providers.downloads/cache/
    Even though I have permission keep failing.

    Any solution how you have downloaded file to any other directory?

  8. arunim2405 commented on Jul 13, 2021

    @arunim2405
    Author

    @arunim2405
    I tried to save file directly as you mentioned path : RNFS.ExternalDirectoryPath +'/certificate.pdf',.

    `
    ReactNativeBlobUtil.config({

      path: RNFS.ExternalDirectoryPath + 'receipt.pdf',
    
      addAndroidDownloads: {
    
        useDownloadManager: true,
    
        notification: true,
    
        mime: 'application/pdf',
    
        description: 'Downloading Receipt.',
    
        mediaScannable: true,
    
      },
    
      overwrite: false,
    
    })`
    

    But it keeps saving file in /data/data/com.android.providers.downloads/cache/
    Any Idea?

    You seem to have missed '/' in '/receipt.pdf'

  9. Kamani commented on Jul 14, 2021

    @Kamani

    @arunim2405 I am sorry man but honestly I tried that as well not working.
    I am not sure how it's working for you.
    Are you using Expo? I am not using it.
    Is there any way you can show some demo? Honestly I really appreciate your help.
    I have also taken access rights before. But it keeps downloading in default directory.

  10. Kamani commented on Jul 14, 2021

    @Kamani

    @RonRadtke
    I think you can breakdown this feature and it will be really helpful.
    First supporting for only downlod or upload from default download directory. This will be really good enhancement.

  11. arunim2405 commented on Jul 14, 2021

    @arunim2405
    Author
     ReactNativeBlobUtil.config({
            addAndroidDownloads : {
                useDownloadManager : true, // <-- this is the only thing required
                notification : true,
                path : RNFS.ExternalDirectoryPath +'/certificate.pdf',
                // Optional, override notification setting (default to true)
                //fileCache : false,
                title : 'Cowin Certificate downloaded',
                mediaScannable : true,
                // Optional, but recommended since android DownloadManager will fail when
                // the url does not contains a file extension, by default the mime type will be text/plain
                mime : "application/pdf",
                description : 'Cowin Certificate.'
            }
        })
        .fetch('GET', `https://cdn-api.co-vin.in/api/v2/registration/certificate/public/download?beneficiary_reference_id=${this.state.beneficiary}`,{
            Accept: 'application/json',
            "Authorization":`Bearer ${token}`,
            'Content-Type': 'application/json',
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
          })
        .then((resp) => {
          // the path of downloaded file
          console.log(resp.path())
          android.actionViewIntent(resp.path(), 'application/pdf')
          AlertClass.showAlert(
            "CASAMED",
            "Your certificate was downloaded. Check out our app more for access to customised physiotherapy plans.",
            [
                {
                    text: "Go to Home",
                    onPress: () => {
                        
                        this.props.navigation.navigate("HomeScreen");
                    },
                },
    
                {
                    text: "Download another Certificate",
                    onPress: () =>  {
                        
                        
                       // this.props.navigation.navigate("MyExcercise", { item, selectedDate });
                
                },
                    style: "cancel",
                },
            ]
        );
            console.log(resp)
        }).catch(e=>{
            console.log(e)
        })
  12. arunim2405 commented on Jul 14, 2021

    @arunim2405
    Author

    @Kamani Here is the full logic I am using.

  13. Kamani commented on Jul 14, 2021

    @Kamani

    @arunim2405 Found issue. I have given path before addAndroidDownloads.
    While to make it work need to give path inside addAndroidDownloads.
    Thank you so much man.

    Infact I think we should atleast update this document.
    Because in document https://github.com/RonRadtke/react-native-blob-util#download-example-fetch-files-that-need-authorization-token as well they mentioned to give path directly and not inside addAndroidDownloads.

    @RonRadtke I think this should be updated in document.

  14. Kamani commented on Jul 14, 2021

    @Kamani

    @RonRadtke Infact document contains many links which are resolving to 404. That should be also removed. If document will be clear I do think lot's of developer's will find it helpful.

  15. RonRadtke commented on Jul 14, 2021

    @RonRadtke
    Owner

    The documentation for sure could use a clean up. You're right about that.
    The link you posted is not linking to the correct url.
    And it is correct that the path is outside in this example.

    Have a look at this part: https://github.com/RonRadtke/react-native-blob-util#android-media-scanner-and-download-manager-support

    The outer path is only used if you don't use the addAndroidDownloads, if you're using the DonwnloadManager you need to specify the path within the addAndroidDownloads section.

  16. anniewey commented on Dec 8, 2023

    @anniewey

    @RonRadtke I'm seeing this issue in "react-native-blob-util": "0.19.4"

    Tried different dirs (DownloadDir, DocumentDir, CacheDir) but getting the same error.

    WARN  Possible Unhandled Promise Rejection (id: 10):
    Error: Failed to find configured root that contains /data/data/com.android.providers.downloads/cache/sample-18.pdf
    

    My config:

    const fileName = `Resources-${Date.now()}.pdf`;
    const dirs = ReactNativeBlobUtil.fs.dirs;
    
        ReactNativeBlobUtil.config({
          fileCache: true,
          appendExt: 'pdf',
          path: `${dirs.DocumentDir}/${fileName}`,
          addAndroidDownloads: {
            useDownloadManager: true,
            notification: true,
            title: fileName,
            description: 'File downloaded by download manager.',
            mime: 'application/pdf',
            mediaScannable: true,
          },
        })
          .fetch('GET', url)
          .then(async (res) => {
            console.log(res.path());
            setLoading(false);
    
            if (Platform.OS === 'ios') {
              ReactNativeBlobUtil.ios.previewDocument(res.path()); // this is working 
            } else {
              // this is not working 
              ReactNativeBlobUtil.android.actionViewIntent(
                res.path(),
                'application/pdf',
              );
            }
          })
          .catch((err) => {
            setLoading(false);
            console.log(err);
          });
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions