Javascript 解析返回“未定义”的云函数
我正在尝试获取Parse Cloud模块示例,并将其转换为一个单独的方法,而不是像Parse Docs示例中的当前方法那样的一个回调 每次尝试调用该函数时,我都会收到以下消息,然后什么也没有发生: I2015-04-20T23:46:47.073Z]v19:Ran云功能 用户uX9PTGGfji的generateProfilePhotoThumbnail:输入: {objectId:uX9PTGGfji}结果:未定义 我不是Javascript高手。我想我犯了一些错误。请,有人可以检查我的代码并教我怎么了?谢谢Javascript 解析返回“未定义”的云函数,javascript,parse-platform,Javascript,Parse Platform,我正在尝试获取Parse Cloud模块示例,并将其转换为一个单独的方法,而不是像Parse Docs示例中的当前方法那样的一个回调 每次尝试调用该函数时,我都会收到以下消息,然后什么也没有发生: I2015-04-20T23:46:47.073Z]v19:Ran云功能 用户uX9PTGGfji的generateProfilePhotoThumbnail:输入: {objectId:uX9PTGGfji}结果:未定义 我不是Javascript高手。我想我犯了一些错误。请,有人可以检查我的代码并
var Image = require("parse-image");
Parse.Cloud.define("generateProfilePhotoThumbnail", function(request, response) {
var query = new Parse.Query(Parse.User);
query.equalTo("objectId", request.params.objectId);
query.first({
success: function(foundUser) {
var user = foundUser;
Parse.Cloud.httpRequest({
url: user.get("profilePhoto").url()
}).then(function(response) {
var image = new Image();
return image.setData(response.buffer);
}).then(function(image) {
// Crop the image to the smaller of width or height.
var size = Math.min(image.width(), image.height());
return image.crop({
left: (image.width() - size) / 2,
top: (image.height() - size) / 2,
width: size,
height: size
});
}).then(function(image) {
// Resize the image to 64x64.
return image.scale({
width: 64,
height: 64
});
}).then(function(image) {
// Make sure it's a JPEG to save disk space and bandwidth.
return image.setFormat("JPEG");
}).then(function(image) {
// Get the image data in a Buffer.
return image.data();
}).then(function(buffer) {
// Save the image into a new file.
var base64 = buffer.toString("base64");
var cropped = new Parse.File("thumbnail.jpg", { base64: base64 });
return cropped.save();
}).then(function(cropped) {
// Attach the image file to the original object.
user.set("profilePhotoThumbnail", cropped);
}).then(function(result) {
response.success(result);
}, function(error) {
response.error(error);
});
},
error: function(error) {
response.error("generateProfilePhotoThumbnail failed" + error);
}
});
});
从外观上看,query.first是一个异步调用,函数在进行此调用后返回,因此结果未定义。试一试
query.first().then(function(foundUser){
//put rest of your code here
}, function(error) {
response.error(error);
});