question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Permission denied

See original GitHub issue

HI, I am working on react-native new version, I have implement the html converter to pdf and got the base64 data. I have tried to download file in my Download folder. I am try download using this library but get the Permission denied error. I am add a android permissions, WRITE_EXTERNAL_STORAGE and <action android:name="android.intent.action.DOWNLOAD_COMPLETE"/>

But got the this error:

Error: Permission denied
    at Object.fn [as writeFile] (index.bundle?platfor…&minify=false:10730)
    at Object.writeFile (index.bundle?platfor…minify=false:334448)

Code:

createAndSavePDF = async() => {
        let options = {
            html: '<h1>This is a test PDF</h1>',
            fileName: 'test',
            directory: 'Download',
            base64: true
        };
        let file = await RNHTMLtoPDF.convert(options)

        // RNFetchBlob.fs.dirs.DownloadDir it's getting the download folder from internal storage
        let filePath = RNFetchBlob.fs.dirs.DownloadDir + '/testPDF.pdf';
        
        RNFetchBlob.fs.writeFile(filePath, file.base64, 'base64')
            .then(response => {
                console.log('Success Log: ', response);
            })
            .catch(errors => {
                console.log(" Error Log: ", errors);
            })
    }

I am working on debug mode on system.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

15reactions
Peretz30commented, Feb 17, 2020

On Android 10, you should to ask permissions through PermissionsAndroid

Try something like:

createAndSavePDF = async() => {
try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
      {
        title: 'Cool Photo App Camera Permission',
        message:
          'Cool Photo App needs access to your camera ' +
          'so you can take awesome pictures.',
        buttonNeutral: 'Ask Me Later',
        buttonNegative: 'Cancel',
        buttonPositive: 'OK',
      },
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      console.log('You can use the camera');
 let options = {
            html: '<h1>This is a test PDF</h1>',
            fileName: 'test',
            directory: 'Download',
            base64: true
        };
        let file = await RNHTMLtoPDF.convert(options)

        // RNFetchBlob.fs.dirs.DownloadDir it's getting the download folder from internal storage
        let filePath = RNFetchBlob.fs.dirs.DownloadDir + '/testPDF.pdf';
        
        RNFetchBlob.fs.writeFile(filePath, file.base64, 'base64')
            .then(response => {
                console.log('Success Log: ', response);
            })
            .catch(errors => {
                console.log(" Error Log: ", errors);
            })
    } else {
      console.log('Camera permission denied');
    }
  } catch (err) {
    console.warn(err);
  }
       
    }
14reactions
Pyroboomkacommented, Feb 7, 2020

Got the same problem in Android 10 when trying to copy a file with cp to Downloads directory.

    <application
        ...
        android:requestLegacyExternalStorage="true"
       ...
</application>

in AndroidManifesl.xml seems to help. Don’t know if it is the issue with the library.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve the "Permission Denied" error in Linux
While using Linux, you may encounter the error, “permission denied”. This error occurs when the user does not have the privileges to make...
Read more >
How to fix 'permission denied' error in Linux? [Solutions]
This type of error will occur whenever you run a command for which you do not have the execute permission. Similarly, you cannot...
Read more >
How to Fix Shell Script Permission Denied Error in Linux
To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode)...
Read more >
How to solve the bash: permission denied error?
The permission denied error is encountered when the script you are running does not have the execute permission. Unix and similar operating systems...
Read more >
Troubleshoot "Permission denied (Publickey)" or ...
You're trying to connect using the wrong user name for your AMI. · The file permissions within the operating system are incorrect on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found