Javascript Phonegap:解析从本机文件选择器获取的content://URI
我正在使用从我的Android设备中选择文件。插件返回一个content://URI(例如。content://com.android.providers.media.documents/document/image%3A15756). 我正在调用resolveLocalFileSystemURI,以便能够解析内容URL并在画布上绘制图像。但是由于某些原因,URI没有被正确解析 例如,返回条目的完整路径是/com.android.providers.media.documents/document/image%3A15756 对于内容URIcontent://com.android.providers.media.documents/document/image%3A15756 有什么想法吗?我的代码如下:Javascript Phonegap:解析从本机文件选择器获取的content://URI,javascript,android,cordova,phonegap-plugins,cordova-plugins,Javascript,Android,Cordova,Phonegap Plugins,Cordova Plugins,我正在使用从我的Android设备中选择文件。插件返回一个content://URI(例如。content://com.android.providers.media.documents/document/image%3A15756). 我正在调用resolveLocalFileSystemURI,以便能够解析内容URL并在画布上绘制图像。但是由于某些原因,URI没有被正确解析 例如,返回条目的完整路径是/com.android.providers.media.documents/documen
window.resolveLocalFileSystemURI(_this.target_image, function (fileEntry) {
var img = new Image();
alert(fileEntry.fullPath);
img.src = URL.createObjectURL(fileEntry.fullPath);
img.onload = function() {
combiner_context.drawImage(img, 0, 0);
combiner_context.putImage(0, img.height, _that.editor_img);
};
}, function () {
alert('Could not load selected file. Please try again.');
});
我能够使用以下插件将“content://”URI转换为“file://”URI: 在获得“file://”URI之后,我就可以使用Cordova的resolveLocalFileSystemURL()函数了 希望这有帮助
if (fileUri.startsWith("content://")) {
//We have a native file path (usually returned when a user gets a file from their Android gallery)
//Let's convert to a fileUri that we can consume properly
window.FilePath.resolveNativePath(fileUri, function(localFileUri) {
window.resolveLocalFileSystemURL("file://" + localFileUri, function(fileEntry) {/*Do Something*/});
});
}
不一定有您可以访问的文件。该插件没有实现“文件选择器”,尽管它的名称是。它实现了一个内容选择器,使用Android的
ACTION\u GET\u content
。返回的(您的内容://
值)是一个Uri
,本机Java应用程序将使用该Uri获取输入流
,以读取所选内容。没有要求Uri
是一个您可以访问的文件,并且随着Android操作系统的不断发布,它成为您可以访问的文件的几率会降低。我明白了。访问的文件来自gallery,我的应用程序可以访问gallery…您有推荐的其他插件吗?抱歉,我没有推荐给您。已解决:我尝试了,它正在工作,但如果我尝试复制或读取该文件,我会遇到安全错误。我想从Android上的Outlook获取文件内容。