Cordova:从内容 Uri 获取文件 Uri
Cordova: Getting a file Uri from a content Uri
我用 Apache Cordova 实现了一个应用程序,我使用了 $cordovaCamera 插件。
当 $cordovaCamera 的源类型为 Camera.PictureSourceType.PHOTOLIBRARY 时,输出类似于
"content://com.android.providers.media.documents/document/image"
并且,当我使用 Camera.PictureSourceType.CAMERA 时,我得到
"file:///storage/emulated/0/Android/data/com.ionic.viewapp/cache/image.jpg".
在我的例子中,格式 "file://.." 更有用。
是否可以从内容 URI 中获取文件 URI?
我找到了这个问题的许多答案,但所有答案都是针对 JAVA,而不是针对 Javascript。
我发现了问题。
我正在使用 Ionic 和 Ionic View 在设备中进行测试。
当我尝试 cordova-plugin-filepath 时,它不起作用。但是我发现问题是在Ionic View中这个插件失败了。
所以,我在服务中写了这个函数:
// data is the return of $cordovaCamera.getPicture.
getFilePath: function(data){
var deferred = $q.defer();
window.FilePath.resolveNativePath(data, function(result) {
deferred.resolve('file://' + result;);
}, function (error) {
throw new Error("");
});
return deferred.promise;
}
到return我需要的文件URI。
然后,我在 phone 中安装了 apk,它可以运行。
现在,我可以存储从相机或画廊获得的图像并上传到服务器。
以上回答有误
window.FilePath.resolveNativePath
成功后,其结果已经有格式:file:///...
,所以不需要前置file://
.
我用 Apache Cordova 实现了一个应用程序,我使用了 $cordovaCamera 插件。 当 $cordovaCamera 的源类型为 Camera.PictureSourceType.PHOTOLIBRARY 时,输出类似于
"content://com.android.providers.media.documents/document/image"
并且,当我使用 Camera.PictureSourceType.CAMERA 时,我得到
"file:///storage/emulated/0/Android/data/com.ionic.viewapp/cache/image.jpg".
在我的例子中,格式 "file://.." 更有用。
是否可以从内容 URI 中获取文件 URI?
我找到了这个问题的许多答案,但所有答案都是针对 JAVA,而不是针对 Javascript。
我发现了问题。 我正在使用 Ionic 和 Ionic View 在设备中进行测试。
当我尝试 cordova-plugin-filepath 时,它不起作用。但是我发现问题是在Ionic View中这个插件失败了。
所以,我在服务中写了这个函数:
// data is the return of $cordovaCamera.getPicture.
getFilePath: function(data){
var deferred = $q.defer();
window.FilePath.resolveNativePath(data, function(result) {
deferred.resolve('file://' + result;);
}, function (error) {
throw new Error("");
});
return deferred.promise;
}
到return我需要的文件URI。 然后,我在 phone 中安装了 apk,它可以运行。 现在,我可以存储从相机或画廊获得的图像并上传到服务器。
以上回答有误
window.FilePath.resolveNativePath
成功后,其结果已经有格式:file:///...
,所以不需要前置file://
.