2016-02-10 57 views
0

我有一個Cloudant數據庫,它有一個圖像作爲文檔的附件。示例文檔如下所示Bluemix Connect and Compose

{ 
    "_attachments": { 
     "smiley.png": { 
      "content_type": "image\/png", 
      "digest": "md5-Xxwpc\/\/87878gthgygf==", 
      "length": 25148, 
      "revpos": 2, 
      "stub": true 
     } 
    }, 
    "_rev": "4-08f5ecebd8024a967706564972f31f79", 
    "id": "3e88e50d5a7095897d4544d3ed4118ab", 
    "age": 10, 
    "name": "Smiley", 
    "dob": 10102000, 
    "gender": "male", 
    "gadget": "watch" 
    } 

使用Connect和Compose創建的API用於基本的CRUD操作。我使用API​​添加了數據,附件使用了Cloudant儀表板並添加了圖像作爲附件。 現在,當我在JavaScript代碼中使用REST API檢索數據時,我可以像上面那樣檢索JSON並獲取所有細節。我不確定如何獲取圖像並將其顯示在我的網頁中。

function getCatalog() 
{ 
    var input = { 
      method : 'get', 
      returnedContentType : 'application/json', 
      path : 'connect-api-prod-dfd-cc0e-11e5-b246-ffdf/connect_compose/031bcc30-cc0e-11e5-b246-8fd1e5139db0/user_db', 
      parameters : { 

      }, 
      headers : { 
       "X-IBM-CloudInt-ApiKey" : "HHURI1FJTkFLT0ZZZzdWTFQ1OUYyTkIxSERIuvehisDhWSEM4RksyWg==" 
      } 
    }; 

    var response = WL.Server.invokeHttp(input); 
    return response; 
} 

任何幫助,將不勝感激。

回答

0

如上所述here

要提取附件,進行GET請求到https://$USERNAME.cloudant.com/$DATABASE/$DOCUMENT_ID/$ATTACHMENT。回覆的主體是附件的原始內容。

因此,在你上面的例子中路徑的結合會是:

connect-api-prod-dfd-cc0e-11e5-b246-ffdf/connect_compose/031bcc30-cc0e-11e5-b246-8fd1e5139db0/user_db/3e88e50d5a7095897d4544d3ed4118ab/smiley.png 
+0

我試過了,如果它是Cloudant直接調用的作品。由於我正在通過連接和撰寫給我一個錯誤消息。 – Zorro

相關問題