cordova-plugin-file icon indicating copy to clipboard operation
cordova-plugin-file copied to clipboard

FileError {code: 5, message: "ENCODING_ERR"}

Open manel00 opened this issue 2 years ago • 3 comments

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 avatar Jul 26 '21 14:07 manel00

@manel00 did you find a solution to this?

CodeWithOz avatar Nov 06 '21 14:11 CodeWithOz

any solution?

sajath-45 avatar Jan 24 '22 11:01 sajath-45

replace the invalid characters in the fileName like fileName.replace( /(?:^(PRN|AUX|CLOCK$|NUL|CON|COM\d|LPT\d|..)(?:.(?=.)|$)|(?:([\x00-\x1f\?:"";|/])))/g, '_')

alexis009 avatar Apr 12 '22 04:04 alexis009

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.

breautek avatar Jan 25 '23 00:01 breautek