Ionic3:error File name too lang in encode base64

I have this error when I encode the file to base64 when I use plugin convert to base64 in doc ionic.

error:

code angular:

testup()
{
for(var s of this.files)
{
  this.imgarr.push(s);
}
console.log(this.imgarr);
for(var o of this.imgarr)
{
this.base64.encodeFile(o.name).then((base64File: string) => {
alert(base64File);
this.base64array.push(base64File);

} , (err) => {
  this.presentToast(err);
  this.presentToast('error encode');
});       


}

this.http.post('url api',this.base64array, {responseType: 'text'}).subscribe(res =>
 alert(res),
        err => {
          this.presentToast(err);
        });
}

the string is not sent to API because File name is long what is the solution to send the filename?

Did u get it work?
If yes, can u please share what did u do?
I am facing same problem.

Thanks

@chaymaveganet
this function for get base64 :

_handleReaderLoaded(readerEvt) {
		     var binaryString = readerEvt.target.result;
		     this.base64textString= btoa(binaryString);
		      this.base64array.push(this.base64textString);
		      this.http.post('url api',this.base64array, {responseType: 'text'}).subscribe(res =>
		 alert(res),

		        err => {
		          this.presentToast(err);
		        });

		this.base64array = [];

		    }

and this function for copie file from object file to array then use function for convert to base64 :

testup()
			{

			for(var s=0;s< this.files.length;s++)
			{
			  this.imgarr.push(this.files[s]);
			}

			for(var o of this.imgarr)
			{
			  var reader = new FileReader();
			  reader.onload =this._handleReaderLoaded.bind(this);
			  reader.readAsBinaryString(o);
			}

			this.imgarr = [];

1 Like