Javascript TypeError:无法调用方法';然后';未定义在Object.Parse.File.save的
我正在从Angular js应用程序中使用parse.com的js api。我正在尝试保存/更新用户的个人资料图片。我有以下代码: 一些htmlJavascript TypeError:无法调用方法';然后';未定义在Object.Parse.File.save的,javascript,angularjs,parse-platform,promise,Javascript,Angularjs,Parse Platform,Promise,我正在从Angular js应用程序中使用parse.com的js api。我正在尝试保存/更新用户的个人资料图片。我有以下代码: 一些html <input type="file" capture="camera" accept="image/*" id="profilePhotoFileUpload"> 我不断地发现这个错误: TypeError:无法调用未定义的方法“then” 在Object.Parse.File.save(Parse-1.2.8.js:4084:43)
<input type="file" capture="camera" accept="image/*" id="profilePhotoFileUpload">
我不断地发现这个错误:
TypeError:无法调用未定义的方法“then”
在Object.Parse.File.save(Parse-1.2.8.js:4084:43)
调用parseFile.save()时
基本上_源是未定义的。为什么
谢谢 我终于解决了这个问题,因为我的最终目标是将它与phonegap一起使用。非常感谢雷蒙德·卡姆登 函数gotPic(数据){
window.resolveLocalFileSystemURI(数据、函数(条目){
var reader=new FileReader();
reader.onloadend=函数(evt){
var byteArray=新的Uint8Array(evt.target.result);
var输出=新数组(byteArray.length);
var i=0;
var n=输出长度;
而(i
}如果其他人正在使用Phonegap和Parse,下面是Raymond Camden提供的另一个有用的示例,它拍摄了一张照片: 它会像这样保存:
var parseFile = new Parse.File("mypic.jpg", {base64:imagedata});
console.log(parseFile);
parseFile.save().then(function() {
var note = new NoteOb();
note.set("text",noteText);
note.set("picture",parseFile);
note.save(null, {
success:function(ob) {
$.mobile.changePage("#home");
}, error:function(e) {
console.log("Oh crap", e);
}
});
cleanUp();
}, function(error) {
console.log("Error");
console.log(error);
});
特别要注意{base64:imagedata}
,因为这是使用如下字符串数据创建解析文件的关键
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');
});
});
var imagedata = "";
$("#takePicBtn").on("click", function(e) {
e.preventDefault();
navigator.camera.getPicture(gotPic, failHandler,
{quality:50, destinationType:navigator.camera.DestinationType.DATA_URL,
sourceType:navigator.camera.PictureSourceType.PHOTOLIBRARY});
});
function gotPic(data) {
console.log('got here');
imagedata = data;
$("#takePicBtn").text("Picture Taken!").button("refresh");
}
var parseFile = new Parse.File("mypic.jpg", {base64:imagedata});
console.log(parseFile);
parseFile.save().then(function() {
var note = new NoteOb();
note.set("text",noteText);
note.set("picture",parseFile);
note.save(null, {
success:function(ob) {
$.mobile.changePage("#home");
}, error:function(e) {
console.log("Oh crap", e);
}
});
cleanUp();
}, function(error) {
console.log("Error");
console.log(error);
});