gpt4 book ai didi

android - ionic 文件选择器 URL 问题

转载 作者:行者123 更新时间:2023-11-29 02:25:26 27 4
gpt4 key购买 nike

我正在使用这个插件来获取文件
https://ionicframework.com/docs/native/file-chooser/

当我从 Downloads 文件夹中选择一个 PDF 文件时,它会给我一个 URI,例如 content://com.android.providers.downloads.documents/文档/1015

但如果我选择另一个文件,如 ZIPPNG,它会解析为合适的路径

content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fwws.zip

content://com.android.providers.downloads.documents/document/raw%3A%2Fstorage%2Femulated%2F0%2FDownload%2Fopacity.png

如何从 file://... 形式的文件中获取路径。

我已经尝试了以下方法但没有成功:

FilePath.resolveNativePath

normalizeURL

更新:

导入

import { File } from '@ionic-native/file';
import { FileChooser } from '@ionic-native/file-chooser'
import { FilePath } from '@ionic-native/file-path';

文件选择器代码:

  getAndroidFile() {

this.fileChooser.open()
.then(uri => {
console.log("uri", uri);
this.file.resolveLocalFilesystemUrl(uri).then((files) => {
console.log("files", files);
}).catch((error) => { console.log("error", error) });
(<any>window).FilePath.resolveNativePath(uri, (result) => {
this.nativepath = result;
console.log("nativepath", this.nativepath);
}, (err) => {
console.log("err", err);
})
})
}

我按照 Aaron 的建议使用了它:

this.file.resolveLocalFilesystemUrl(uri).then((files)=>{
console.log("files",files);
}).catch((error) => { console.log("error", error) });

它仍然返回:

filesystem: FileSystem {name: "content", root: DirectoryEntry}
fullPath: "/com.android.providers.downloads.documents/document/1015"
isDirectory: false
isFile: true
name: "1015"
nativeURL: "content://com.android.providers.downloads.documents/document/1015"

这是原始网址。

更新 2:

getBase64Content(nativepath) {
let path = nativepath.substring(0, nativepath.lastIndexOf('/'));
let filename = nativepath.substring(nativepath.lastIndexOf('/'), nativepath.length);
filename = filename.replace("/", "");
console.log("path", path);
console.log("filename", filename);
this.file.readAsDataURL(path, filename)
.then(content => {
console.log('content1', content);
//this will be passed to web API
this.base64content = content;

})
.catch(err => {
console.log("err", err);
})

这个 base64 内容通过 api 发送到服务器,然后他们将其转换回文件。

更新 3:抱歉回复晚了,真的忙于另一个项目。Koken 的答案:

你如何测试这个东西?您使用什么命令执行? ionic Cordova 运行安卓(我使用 chrome 通过远程调试来检查这些值。)

安卓模拟器?安卓设备?安卓设备。 Redmi note 5 pro(MIUI 10, Android 8.1).

另外...选择文件后接下来的步骤是什么?此 base64 内容通过 api 发送到服务器,然后他们将其转换回文件。

希望大家帮帮我。给出代码。谢谢

最佳答案

您需要 FileManager 插件中的 resolveLocalFilesystemUrl

https://ionicframework.com/docs/native/file/#resolveLocalFilesystemUrl

关于android - ionic 文件选择器 URL 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52512275/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com