Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IONIC 3 IOS can't read data from file

I am using this file picker to upload files to my server:

https://github.com/jcesarmobile/FilePicker-Phonegap-iOS-Plugin

My server takes base64 files, so I need to convert the file I uploaded. I am doing that using the file plugin mentioned in the ionic docs. So my code looks like this:

uploadIOS(){
    var self=this

    let utis = ["public.data"]

    FilePicker.pickFile(
        function (uri) {
            let correctPath = uri.substr(0, uri.lastIndexOf('/') + 1);
            let currentName = uri.substring(uri.lastIndexOf('/') + 1);

            self.file.readAsDataURL(correctPath, currentName).then(result=>{
                    console.log ('reading data ' + JSON.stringify(result))
                }).catch((err)=>{
                    console.log ('err4' + JSON.stringify(err))
                })
        },
        function (error) {
            console.log(JSON.stringify(error));
        },
        function (utis) {
            console.log('UTIS', this.utis)
        }
    )
}

but when I upload from Google Drive, or iCloud Drive or DropBox it returns

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

like image 800
noor Avatar asked Aug 16 '17 05:08

noor


1 Answers

let self = this;
self.filePicker.pickFile().then(uri => {

let correctPath = uri.substr(0, uri.lastIndexOf('/') + 1);
let currentName = uri.substring(uri.lastIndexOf('/') + 1);
self.file.readAsDataURL("file:///" + correctPath, currentName).then(result=>{                           


})

I have fixed this issue using this code.

like image 158
jitendra Avatar answered Sep 22 '22 07:09

jitendra