gpt4 book ai didi

android - 从 cordova 中的 MediaType.ALLMEDIA 获取 "file:///storage"路径

转载 作者:行者123 更新时间:2023-11-29 19:15:21 24 4
gpt4 key购买 nike

我需要在我的应用程序中上传所有类型的文件,对于我需要获取图像高度和宽度的图像,我正在使用:

$scope.uploadFile = function(){
$scope.imageUploading = true;
var options = {
quality: 70,
//~ targetWidth: 1005,
//~ targetHeight: 693,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
mediaType: Camera.MediaType.PICTURE,
correctOrientation: true
};
$cordovaCamera.getPicture(options).then(function(imageData) {
imageData = imageData.split('?');
var imageURI = imageData[0];
// This function is called once an imageURI is rerturned from PhoneGap's camera or gallery function
window.resolveLocalFileSystemURL(imageURI, function(fileEntry) {
fileEntry.file(function(fileObject){
// Create a reader to read the file
var reader = new FileReader();
// Create a function to process the file once it's read
reader.onloadend = function(evt) {
// Create an image element that we will load the data into
var image = new Image()
image.onload = function(evt) {
// The image has been loaded and the data is ready
var image_width = this.width
var image_height = this.height
if(parseInt(image_width) < confArr.image_sizes.portfolio.large.w || parseInt(image_height) < confArr.image_sizes.portfolio.large.h){
Auth.toastMessage($rootScope.appMainLang.formvalidation.upload_resolution_limit.replace('%s',parseInt(confArr.image_sizes.portfolio.large.w)),'long','center');
$scope.imageUploading = false;
$ionicLoading.hide();
}else{
$scope.imageUploading = true;
$scope.jrCrop(imageURI);
}
image = null
}
// Load the read data into the image source. It's base64 data
image.src = evt.target.result
}
// Read from disk the data as base64
reader.readAsDataURL(fileObject)
}, function(){
Auth.toastMessage("There was an error reading or processing this file.","long", "center");
})
})


}, function(err) {
$scope.imageUploading = false;
$ionicLoading.hide();
// Auth.toastMessage(Auth.getlocal("timeoutText","string"),"long", "center");
});
}

当我使用 媒体类型: Camera.MediaType.PICTURE,

在上面的代码中,它将文件路径返回为“file:///storage/emulated/0/....”并且工作正常。但由于我需要上传所有类型的文件,所以我将上面的行替换为

mediaType: Camera.MediaType.ALLMEDIA

并且此文件路径变为“/storage/emulated/0/...”,然后它不会进入“window.resolveLocalFileSystemURL”函数。那么有没有办法将后面的路径转换为上面提到的类似路径?

最佳答案

只需将 file://添加到字符串中。像这样:

var imageURI = 'file://' + imageData[0];

关于android - 从 cordova 中的 MediaType.ALLMEDIA 获取 "file:///storage"路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43719158/

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