Code Monkey home page Code Monkey logo

Comments (16)

RonRadtke avatar RonRadtke commented on June 21, 2024 3

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

from react-native-blob-util.

arunim2405 avatar arunim2405 commented on June 21, 2024 2

@Kamani Here is the full logic I am using.

from react-native-blob-util.

arunim2405 avatar arunim2405 commented on June 21, 2024 1

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

from react-native-blob-util.

arunim2405 avatar arunim2405 commented on June 21, 2024 1

@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'

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024 1

@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.

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024 1

@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.

from react-native-blob-util.

RonRadtke avatar RonRadtke commented on June 21, 2024

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

from react-native-blob-util.

arunim2405 avatar arunim2405 commented on June 21, 2024

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?

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024

@arunim2405 how you saved file to your app directory?

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024

@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?

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024

@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?

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024

@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.

from react-native-blob-util.

Kamani avatar Kamani commented on June 21, 2024

@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.

from react-native-blob-util.

arunim2405 avatar arunim2405 commented on June 21, 2024
 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)
    })

from react-native-blob-util.

RonRadtke avatar RonRadtke commented on June 21, 2024

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.

from react-native-blob-util.

anniewey avatar anniewey commented on June 21, 2024

@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);
      });

from react-native-blob-util.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.