【问题标题】:Fetching a POST request in Meteor via a notification url通过通知 url 在 Meteor 中获取 POST 请求
【发布时间】:2016-05-03 13:09:18
【问题描述】:

这是我没有经验的。

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

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

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

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

我该怎么做?

【问题讨论】:

    标签: javascript post meteor cloudinary


    【解决方案1】:

    在您的服务器端,设置一个路由(假设您使用的是 Iron-router)来处理来自 cloudinary 的帖子:

    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,那么 cloudinary 通知 url 将是:

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

    【讨论】:

    • 如果你不想添加iron:router(例如,因为你已经在使用flow-router),你也可以使用meteorhacks:picker来设置一个服务端路由。语法略有不同,但概念与此相同。
    • 好东西。我安装了一个 Chrome 应用程序来发送虚拟请求,这样我就可以模拟真实情况并进行一些实验。情况看起来不错!
    • 您还可以使用 3rd 方工具,例如 requestb.in,以便在您的应用程序上设置端点之前进行实验。
    猜你喜欢
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2017-10-30
    • 1970-01-01
    • 2013-04-02
    • 1970-01-01
    • 1970-01-01
    • 2016-05-14
    相关资源
    最近更新 更多