尝试在解析时使用HTTP请求获取图像属性时出错

时间:2015-03-16 08:41:05

标签: image parse-platform httprequest

我收到错误141说对象没有方法"成功'使用以下代码。我只需要从网址获取图片属性。 Attched是Corona SDK的完整错误。enter image description here

Parse.Cloud.define("changePhoto4", function(request, response) {
  var Image = require("parse-image");
  var baseurl = "http://files.parsetfss.com/7bdfab67-db97-4761-936f-be05679ca518/tfss-dc75c8e2-06b6-45fb-bfde-b2befb8ad84a-0.png";
  var params =  {
}
    return Parse.Cloud.httpRequest({
       url: baseurl,
    success: function(response) {
var image = new Image();
    return image.setData(response.buffer, {
      success: function() {
        response.success("Image is " + image.width() + "x" + image.height() + ".");
      },
      error: function(error) {
        response.error(image);
      }
    })
},
    }, 
    function (error) {
        console.error('Console Log response: ' + error.text);
        response.error('Request failed with response ' + error.text)
    });
});

1 个答案:

答案 0 :(得分:0)

Parse.Cloud.define("changePhoto3", function(request, response) {
  var baseurl = "http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg";
  var Image = require("parse-image");
  var params =  {
}
    return Parse.Cloud.httpRequest({
      method: 'POST',
      url: baseurl,
      headers: {
        'Content-Type': 'application/json;charset=utf-8'
      },
      body: params
    }).then(function(httpResponse) {

        var image = new Image();
    return image.setData(httpResponse.buffer, {
      success: function() {
        console.log("Image is " + image.width() + "x" + image.height() + ".");
               response.success(image.width()+"x" + image.height());
      },
      error: function(error) {
        // The image data was invalid.
      }
    })

    }, 
    function (error) {
        console.error('Console Log response: ' + error.text);
        response.error('Request failed with response ' + error.text)
    });
});