gpt4 book ai didi

javascript - 如何上传个人资料图片来解析ionic框架

转载 作者:行者123 更新时间:2023-11-28 06:56:10 25 4
gpt4 key购买 nike

我在上传 html 5、base64 图像进行解析时遇到问题。我创建了几个解析用户和一个 profile_pic 列。此外,我还添加了 cordovacamera 插件来从图库中选择图像并显示它,但我现在想将图像上传到当前用户的 profile_pic 列。

$scope.takePicture = function(){
var options = {
quality: 100,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: Camera.PictureSourceType.PHOTOLIBRARY,
encodingType: Camera.EncodingType.JPEG
}
$cordovaCamera.getPicture(options)
.then(function(data){
console.log('camera date: '+ angular.toJson(data));
$scope.pictureUrl = 'data:image/jpeg;base64,' + data;
var currentUser = Parse.User.current();
currentUser.set("profile_pic", data);
currentUser.save();

}, function(error) {
console.log('camera error: '+ angular.toJson(data));
});
};

是否可以这样做或者是否有其他我可以使用的方法?我能够成功检索列中的图像并显示用户个人资料图片,但是我需要一种上传方法。

  var currentUser = Parse.User.current();
currentUser.fetch().then(function (fetchedUser) {
var name = fetchedUser.getUsername();
var loca = fetchedUser.get('location');
var propic = fetchedUser.get('profile_pic');
var proimage = propic.url();
$scope.username = name;
$scope.location = loca;
$scope.profilepic = proimage;
});

最佳答案

完整源代码在这里 https://github.com/aaronksaunders/dcww/blob/master/www/js/services.js#L33

但基本概念是创建一个文件对象来保存到用户对象中的特定列。

var imageFile = new Parse.File("mypic.jpg", {base64: _params.photo});
imageFile.save().then(function(_f) {
var currentUser = Parse.User.current();
currentUser.set("profile_pic", data);
return currentUser.save();
}).then(function(_user){
return _user;
}, function(_error){
console.log(_error);
};

关于javascript - 如何上传个人资料图片来解析ionic框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32555239/

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