IONIC 3 IOS无法从文件中读取数据 [英] IONIC 3 IOS can't read data from file

查看:678
本文介绍了IONIC 3 IOS无法从文件中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此文件选择器将文件上传到我的服务器:

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


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

我的服务器需要base64文件,所以我需要转换我上传的文件。我正在使用离子文档中提到的文件插件。所以我的代码如下所示:

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)
        }
    )
}

但是当我从Google云端硬盘或iCloud Drive或Drop上传时它返回的框

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


{code:5,message:ENCODING_ERR}

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


推荐答案

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.

这篇关于IONIC 3 IOS无法从文件中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆