IONIC 3 IOS 无法从文件中读取数据

IONIC 3 IOS can#39;t read data from file(IONIC 3 IOS 无法从文件中读取数据)

本文介绍了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 Drive、iCloud Drive 或 DropBox 上传时,它会返回

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 无法从文件中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:IONIC 3 IOS 无法从文件中读取数据

基础教程推荐