I was using cordova-plugin-file-transfer and cordova-plugin-file-chooser on Ionic mobile application to upload some files to Android device which can open with native applications like pdf, word, excel…etc
It is now throwing “exception”:"/storage/emulated/0/Download/pdf-test.pdf: open failed: EACCES (Permission denied)"}".
openFile() {
console.log("openFile");
this.fileChooser.open()
.then(uri => {
console.log(uri)
const fileTransfer: FileTransferObject = this.transfer.create();
let options: FileUploadOptions = {
fileKey: 'files',
fileName: 'name.doc',
params: { resume: uri},
chunkedMode: false,
headers: {
'token': this.token,
'sid': this.sid,
'user': this.user,
'to': this.to,
'node': this.node,
'type': 'doc',
'cap': this.cap
}
}
console.log("Headers" + JSON.stringify(options));
fileTransfer.upload(uri,this.apiurl, options)
.then((data) => {
// success
console.log("Response data ->>>>>>> :- " + JSON.stringify(data));
alert("success" + JSON.stringify(data));
}, (err) => {
// error
console.log("Error data ->>>>>>> :- " + JSON.stringify(err));
alert("error" + JSON.stringify(err));
});
})
.catch(e => console.log(e));
}
i also added permission on AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>