通过通知 url 在 Meteor 中获取 POST 请求

Fetching a POST request in Meteor via a notification url

这是我没有经验的。

在我正在构建的管理页面上,可以将图片上传到名为 Cloudinary 的服务以删除其背景,这个过程最多需要 24 小时,然后他们会发送 POST 请求一些 url 我随请求一起发送的。

这种格式不太适合试验,所以我需要一些帮助。

这是上传图片和发送请求的方式:

Cloudinary.upload(image, {
    folder: "cutouts",
    type: "upload",
    notification_url: "someurl.com"
    background_removal: "remove_the_background"
}, function(error, result) {
       if (!error)
           console.dir(result)
   }
})

问题: notification_url设置什么?即使它在我网站上的某处,我是否需要先部署它才能检查代码是否有效?

根据他们的文档,这是他们将发回的示例:

{ 
  "notification_type": "info",
  "info_kind": "remove_the_background",
  "info_status": "complete",
  "public_id": "wood_chair",
  "uploaded_at": "2014-10-26T11:35:22Z",
  "version": 1414316122,
  "url": 
    "http://res.cloudinary.com/demo/image/upload/v1393688588/wood_chair.jpg",
  "secure_url":
    "https://res.cloudinary.com/demo/image/upload/v1393688588/wood_chair.jpg",
  "etag": "a56e9e88c2add15cac1775c1f687bf73"
}

所以,具体来说,我需要访问 info_statusurl

问题是,我无法进行试验,而且我没有知道如何解决这个问题,因为我根本没有这方面的经验。

如果有帮助的话,这里是他们的文档:http://cloudinary.com/documentation/remove_the_background_image_editing_addon

我该怎么做?

在您的服务器端,设置一个路由(假设您正在使用 iron-router)来处理来自 cloudinary 的 post:

Router.route('/api/cloudinary', { where: 'server' })
    .post(function() {
        var body = this.request.body; // get the body out of the response
        var url = body.url; // based on the JSON you showed
        this.response.statusCode = 200; // set the status code to be returned to cloudinary
        this.response.end(); // send response
    }
);

您可以将 /api/cloudinary/ 更改为您想要的任何内容。如果您的网站是 http://www.example.com,那么云端通知 url 将是:

http://www.example.com/api/cloudinary