嵌套Parse Http请求问题

时间:2015-12-28 21:42:04

标签: javascript parse-platform cloud

我正在使用Parse作为我的应用程序的后端,我想调整所有用户的大小Image,我正在对所有用户运行解析查询,然后调整图像大小。

我遇到问题我的http请求收到错误

  

结果:TypeError:无法调用未定义的方法'url'

我想我应该使用承诺,但我不确定。

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'       在null。 (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       在null。 (Parse.js:3:19941)       在e(Parse.js:2:8941)       在Parse.js:2:9694       在g(Parse.js:2:9431)

0 个答案:

没有答案