NAMUS09 opened a new issue, #577:
URL: https://github.com/apache/cordova-plugin-file/issues/577
# Bug Report
when writing file in this path " window.cordova.file.externalRootDirectory +
'Download' " always throws error in filewriter.onerror. Issue not there in
cordova v11, cordova-android v11 and cordova-plugin-file v7.
## Problem
### What is expected to happen?
It should write the file and return success.
### What does actually happen?
throws error code 2
## Information
<!-- Include all relevant information that might help understand and
reproduce the problem -->
tying to save pdf in download folder. I tried updating the plugin file to
v8. Still issue is there.
### Command or Code
<!-- What command or code is needed to reproduce the problem? -->
private writeToFile(pdfData: BlobPart, fileName: string): Promise<string> {
return new Promise((resolve, reject) => {
var storageLocation = '';
switch (window.cordova.platformId) {
case 'android':
storageLocation = window.cordova.file.externalRootDirectory +
'Download';
break;
case 'ios':
storageLocation = window.cordova.file.documentsDirectory;
break;
}
var folderPath = storageLocation;
console.log(folderPath);
window.resolveLocalFileSystemURL(
folderPath,
(directoryEntry: any) => {
directoryEntry.getFile(
fileName,
{ create: true },
(fileEntry: any) => {
fileEntry.createWriter(
(fileWriter: any) => {
fileWriter.onwriteend = () => {
resolve('success');
console.log('File written successfully.');
};
fileWriter.onerror = (error: any) => {
console.log('Error writing file: ');
reject(error);
};
const dataObj = new Blob([pdfData], { type:
'application/pdf' });
console.log(dataObj);
fileWriter.write(dataObj);
},
() => {
reject('Error creating file writer.');
console.log('Error creating file writer.');
}
);
},
() => {
reject('Error getting file entry.');
console.log('Error getting file entry.');
}
);
},
() => {
reject('Error resolving file system URL.');
console.log('Error resolving file system URL.');
}
);
});
}
### Environment, Platform, Device
<!-- In what environment, on what platform or on which device are you
experiencing the issue? -->
while targeting to api 33 issue occurs. There is no issue in cordova v11
,cordova-android v11 and cordova-plugin-file v7 targeting to api 32.
### Version information
<!--
What are relevant versions you are using?
For example:
Cordova: Cordova CLI, Cordova Platforms, Cordova Plugins
Other Frameworks: Ionic Framework and CLI version
Operating System, Android Studio, Xcode etc.
-->
Cordova CLI v12,
Cordova-android v12
Cordova v8, v7 (both tested)
## Checklist
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [x ] I searched for existing GitHub issues
- [ x] I updated all Cordova tooling to most recent version
- [ x] I included all the necessary information above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]