Javascript 嵌套解析Http请求问题
我正在使用Parse作为我的应用程序的后端,我想调整所有用户图像的大小,我正在对所有用户运行Parse查询,然后调整图像的大小 我遇到了一个问题,我的http请求出错 结果:TypeError:无法调用未定义的方法“url” 我想我应该用承诺,但我不确定Javascript 嵌套解析Http请求问题,javascript,parse-platform,cloud,Javascript,Parse Platform,Cloud,我正在使用Parse作为我的应用程序的后端,我想调整所有用户图像的大小,我正在对所有用户运行Parse查询,然后调整图像的大小 我遇到了一个问题,我的http请求出错 结果:TypeError:无法调用未定义的方法“url” 我想我应该用承诺,但我不确定 Parse.Cloud.job("userMigration", function(request, status) { // Set up to modify user data Parse.Cloud.useMasterKe
Parse.Cloud.job("userMigration", function(request, status) {
// Set up to modify user data
Parse.Cloud.useMasterKey();
var Image = require("parse-image");
var counter = 0;
// Query for all users
var query = new Parse.Query(Parse.User);
query.each(function(user) {
// Update to plan value passed in
Parse.Cloud.httpRequest({
url: user.get("Profilepic").url()
}).then(function(response) {
var image = new Image();
return image.setData(response.buffer);
}).then(function(image) {
// make it fit in 100x100
var width = 100,
height = 100;
if (image.width() > image.height()) {
// work out scaled height
height = image.height() * (100 / image.width());
} else {
// work out scaled width
width = image.width() * (100 / image.height());
}
console.log("..scale to " + width + "x" + height);
return image.scale({
width: width,
height: height
});
}).then(function(scaledImage) {
// get the image data in a Buffer
return scaledImage.data();
}).then(function(buffer) {
// save the image to a new file
console.log("..saving file");
var base64 = buffer.toString("base64");
var name = "Thumbnail.png";
var thumbnail = new Parse.File(name, {
base64: base64
});
return thumbnail.save();
}).then(function(thumbnail) {
// attach the image file to the original object
console.log("..attaching file");
user.set("Profilepic_thumb", thumbnail);
return user.save();
});
}).then(function() {
// Set the job's success status
status.success("Migration completed successfully.");
}, function(error) {
// Set the job's error status
status.error("Uh oh, something went wrong.");
});
});
完全错误
结果:TypeError:无法调用未定义的方法“url”
在空。(main.js:282:33)
在e(Parse.js:2:8941)
在Parse.js:2:9694
at g(Parse.js:2:9431)
在c.extend.then(Parse.js:2:9679)
在main.js:280:29
在空。(Parse.js:3:19941)
在e(Parse.js:2:8941)
在Parse.js:2:9694
at g(Parse.js:2:9431)
您忘记了
返回Parse.Cloud.httpRequest
promise btw。另外,共享错误堆栈也会非常有帮助。我添加了它,Cloud http请求工作正常,但是当它嵌套在查询结果中时,它会显示错误。我想它是user.get(“Profilepic”).url()
。也许user.get(“Profilepic”)
未定义?是的,这就是问题所在这能解决您的问题吗var profilePic=user.get(“profilePic”);如果(!profilePic)返回/*然后稍后*/{url:profilePic.url()}