2016-01-26 54 views
1

這是我沒有經驗的東西。通過通知url獲取流星中的POST請求

在我建立的管理頁面上可以上傳一張圖片到一個名爲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

我該怎麼辦呢?

回答

1

在您的服務器端,建立一個路徑(假設你使用鐵路由器)從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通知網址是:

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

如果你不希望添加鐵:路由器(例如,因爲你已經在使用流量的路由器),你也可以使用meteorhacks :選擇器來設置服務器端路由。語法有點不同,但概念與此相同。 – bluebird

+0

好東西。我安裝了Chrome應用程序發送虛擬請求,以便模擬真實情況並進行一些實驗。事情看起來不錯! – Yeats

+0

您也可以使用第三方工具(如http://requestb.in/),以便在應用程序上設置端點之前進行實驗。 –