rn-fetch-blob
rn-fetch-blob copied to clipboard
Error: Permission denied
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.
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.
android:requestLegacyExternalStorage="true" its not found on targetSDKversion:28
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);
}
}
same issue here on only oppo mobile phones only
I'm also getting the same problem. @Peretz30 I asked for permission as well on the Android side through PermissionAndroid. After allowing permission, it is saying permission denied as an error. Anyone can help?
@Pyroboomka I tried your listed method and now it is working perfect
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.
This one works for me
i already have android:requestLegacyExternalStorage="true" in AndroidManifesl.xml.
i always have permission denied no matter what i do.
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'Storage Permission Required',
message: 'App needs access to your storage to download Photos',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// Once user grant the permission start downloading
console.log('Storage Permission Granted.');
downloadImage();
} else {
// If permission denied then show alert
alert('Storage Permission Not Granted');
}
} catch (err) {
// To handle permission related exception
console.warn(err);
}
any fix in 2023 ? thanks
It's still happening for me. Permission denied after trying everything mentioned here.
same issue here, I have done everything, and not even request is popped up on simulator of android!