cordova-plugin-file
cordova-plugin-file copied to clipboard
FileError {code: 5, message: "ENCODING_ERR"}
Bug Report
Cannot write date and time on the file
Problem
var n = "data_"+new Date().toLocaleDateString()+"_"+new Date().toLocaleTimeString()+".csv" it works perfect but gives error on Ionic when you write a file
What is expected to happen?
To write the file
What does actually happen?
FileError {code: 5, message: "ENCODING_ERR"}
Information
var fileName = "data_"+new Date().toLocaleDateString()+"_"+new Date().toLocaleTimeString()+".csv"
this.file.writeFile(`${this.file.externalRootDirectory}/Download`, fileName, csv, {
replace: true
}).then((res) => {
console.log(res)
}).catch((error) => {
console.log(error)
});
Command or Code
Environment, Platform, Device
Ionic 5, Angular 10
Version information
Checklist
- [ 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
@manel00 did you find a solution to this?
any solution?
replace the invalid characters in the fileName like fileName.replace( /(?:^(PRN|AUX|CLOCK$|NUL|CON|COM\d|LPT\d|..)(?:.(?=.)|$)|(?:([\x00-\x1f\?:"";|/])))/g, '_')
We can't address ionic/angular issues here.
I'd recommend avoid using special characters in file names or file paths however, which those APIs may return depending on the local phone locale.
If the issue persists in a pure cordova app or is reproducible in a minimal reproduction app feel free to create a new issue accordingly.