Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ENCODING_ERR when reading image file from absolute URL

I am following this guide on how to upload an image file using Ionic 3 on an iPhone Simulator. However I am stuck at this error printed from console

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

The code is as follows:

      this.file.resolveLocalFilesystemUrl(dto.image)
        .then((entry: FileEntry) => entry.file(file => {
          const reader = new FileReader();
          reader.onloadend = () => {
            //do something
          };
          reader.readAsArrayBuffer(file);
        }))
        .catch(err => console.log(JSON.stringify(err)));

the value of dto.image is:

/Users/myUsername/Library/Developer/CoreSimulator/Devices/05972D1E-F805-46E4-B164-BB95F116697A/data/Containers/Data/Application/1096409B-6FA3-4660-97AE-EAF3E2472046/tmp/cdv_photo_013.jpg

I am using ionic native File plugin

Thanks in advance.

like image 938
silencer07 Avatar asked Dec 12 '25 05:12

silencer07


1 Answers

seems stupid but this is the solution:

append file:// at the start of the url string so it would work.

so the start will be like file:///Users....

This is not documented but i have guessed from this link

cordova ios resolveLocalFileSystemURL ENCODING_ERR in cordova.file.applicationDirectory

like image 192
silencer07 Avatar answered Dec 15 '25 14:12

silencer07