gpt4 book ai didi

jquery - 获取ImageUri的文件内容

转载 作者:行者123 更新时间:2023-12-03 20:51:19 26 4
gpt4 key购买 nike

我想将从手机拍摄的图像更新到 Parse,我们正在努力解决这个简单的功能,因为我们无法使用 Phonegap 将 ImageUri 转换为真实文件(以便将其上传到我们的 Parse 服务器),我们正在使用 Ripple 来模拟手机行为。

我们尝试过这段代码:

var reader = new FileReader();


reader.onloadend = function(evt) {

console.log("read success");
console.log(evt.target.result);
evt.target.result;
};
reader.readAsText(user.myPicture);

但我收到此错误:TypeError: Object #<Console> has no method 'warning'

似乎phonegap的FileReader不喜欢我从navigator.camera.getPicture()获取的URI类型

$scope.getPicture = function(){

navigator.camera.getPicture(onSuccess, onFail,
//Options => http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html#Camera
{ quality: 50,
destinationType:Camera.DestinationType.FILE_URI,
encodingType: Camera.EncodingType.JPEG,
sourceType : Camera.PictureSourceType.PHOTOLIBRARY ,//CAMERA,
targetWidth: 100,
targetHeight: 100
});
function onSuccess(imageURI) {
var image = document.getElementById('preview');
image.src = imageURI;
$scope.myPicture = image.src;

// $scope.$apply(function() {
// ctrl.$setViewValue(image.src);
// });
}

function onFail(message) {
alert('Failed because: ' + message);
ctrl.$setValidity('Failed because: ' + message, false);
}

};

是否有其他方法可以在不使用 JQuery $.get() 的情况下获取文件?

有一个类似的帖子here有同样的问题

最佳答案

我认为您会欣赏我为您链接的问题得到的相同答案。

with the info in this post 。 。非常感谢雷蒙德·卡姆登!

function gotPic(data) {

window.resolveLocalFileSystemURI(data, function(entry) {

var reader = new FileReader();

reader.onloadend = function(evt) {
var byteArray = new Uint8Array(evt.target.result);
var output = new Array( byteArray.length );
var i = 0;
var n = output.length;
while( i < n ) {
output[i] = byteArray[i];
i++;
}
var parseFile = new Parse.File("mypic.jpg", output);

parseFile.save().then(function(ob) {
navigator.notification.alert("Got it!", null);
console.log(JSON.stringify(ob));
}, function(error) {
console.log("Error");
console.log(error);
});

}

reader.onerror = function(evt) {
console.log('read error');
console.log(JSON.stringify(evt));
}

entry.file(function(s) {
reader.readAsArrayBuffer(s);
}, function(e) {
console.log('ee');
});

});
}

关于jquery - 获取ImageUri的文件内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16559254/

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