将图像上传到Parse时出现问题我试图在用Cordova的camera.getPicture方法捕获图像后将图像保存到Parse。使用cordova的camera.getPicture
下面是运行此示例代码:
// onclick event to take a picture
<button onclick="capturePhoto();"></button>
// function implementation
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL
});
}
// Success callback
function onPhotoDataSuccess(imageData) {
var parseFile = new Parse.File("myPic.jpg", {base64:imageData});
parseFile.save().then(function() {
// The file has been saved to Parse.
}, function(error) {
// The file either could not be read, or could not be saved to Parse.
});
}
如果我简单地设置一个字符串,如在对JavaScript它的工作原理documentation。
var base64 = "V29ya2luZyBhdCBQYXJzZSBpcyBncmVhdCE=";
var file = new Parse.File("myfile.txt", { base64: base64 });
有人可能会指出我在正确的方向或给出一个备用的实施。
谢谢。
谢谢你这么这么这么多! –