您目前查看的是 Apigee Edge 說明文件。
前往 Apigee X 說明文件。 info
版本:2.0.2
列出、下載 Cloud Storage bucket 中的檔案,並為這些檔案產生簽署網址。
這項內容提供設定及使用這項擴充功能的參考資料。如要透過 API Proxy 使用這項擴充功能,請務必先完成下列步驟:
將物件上傳至 bucket。
授予權限,允許代表 Google Cloud Storage 擴充功能的 Google Cloud 服務帳戶存取 bucket。如要進一步瞭解要使用的角色,請參閱「Cloud Storage 角色」。如要進一步瞭解 Cloud Storage 的權限,請參閱「使用身分與存取權管理 (IAM) 權限」。
關於 Cloud Storage
Cloud Storage 是一項服務,可提供安全、耐用且可擴充的檔案儲存空間。如果您剛開始使用 Cloud Storage,建議先參閱 Cloud Storage 說明文件中的快速入門導覽課程。
範例
下列範例說明如何使用 ExtensionCallout 政策,設定支援 Cloud Storage 擴充功能動作。
可列出檔案
在下列範例中,擴充功能的 listFiles 動作會擷取檔案清單,並以陣列形式傳回。listFiles 動作不會採用任何輸入參數。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="false" enabled="true" name="Get-Storage-File-List">
<DisplayName>Get Storage File List</DisplayName>
<Connector>cloud-storage-extension-example</Connector>
<Action>listFiles</Action>
<Input><![CDATA[{}]]></Input>
<Output parsed="false">storage.filelist.retrieved</Output>
</ConnectorCallout>
回應值如下所示:
["example-text.txt","example-image.png"]
下列「指派訊息」政策會從 ExtensionCallout 政策擷取回應值,並複製到回應酬載中。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Storage-File-List">
<DisplayName>Assign Storage File List</DisplayName>
<AssignTo type="response" createNew="false"/>
<Set>
<Payload contentType="application/json">{storage.filelist.retrieved}</Payload>
</Set>
</AssignMessage>
下載檔案
下列 ExtensionCallout 政策會使用 Google Cloud Storage 擴充功能下載文字檔,內容為 Some example text.,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="false" enabled="true" name="Download-File">
<DisplayName>Download File</DisplayName>
<Connector>cloud-storage-extension-example</Connector>
<Action>downloadFile</Action>
<Input><![CDATA[{"fileName": "example-text.txt"}]]></Input>
<Output>storage.file.retrieved</Output>
</ConnectorCallout>
回應值如下所示:
{"content":"Some example text."}
下列「指派訊息」政策會擷取擴充功能傳回的值,並複製到回應酬載中。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Storage-File-List">
<DisplayName>Assign Storage File List</DisplayName>
<AssignTo type="response" createNew="false"/>
<Set>
<Payload contentType="application/json">{storage.file.retrieved}</Payload>
</Set>
</AssignMessage>
產生已簽署的網址
下列 ExtensionCallout 政策會使用這項擴充功能,產生從 Cloud Storage bucket 下載指定檔案的網址。並傳遞檔案名稱,以及網址失效的日期。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ConnectorCallout async="false" continueOnError="false" enabled="true" name="Get-Signed-URL">
<DisplayName>Get Signed URL</DisplayName>
<Connector>cloud-storage-extension-example</Connector>
<Action>generateSignedURL</Action>
<Input><![CDATA[{
"fileName" : "example-text.txt",
"expiresOn" : "2018-08-05"
}]]></Input>
<Output>storage.url.retrieved</Output>
</ConnectorCallout>
擴充功能的傳回值如下所示。
{"url":"https://storage.googleapis.com/storage-extension-example/example-text.txt?GoogleAccessId=extension-test%40my-test-33333.iam.gserviceaccount.com&Expires=1533427200&Signature=Y1cE1DCHesWeIZILRhdIuDR%2FhzZXZ%2BPeY3J1PUkRiosFYj41itHBWh2%2BTQgH9kI6E8s2mWrVDFU43YR7s8Tm9W5VgWRwh0nXSactQ0xKbkKbGZmCcWxgIscOezc1zc%2Bp7lnXSx1qd4wIlIKVH4KCd9WLx4qB1dLxGNxMKB32tA3dio5IiMXaHEA%2FR2fYc0Pjh45t8L5rilk5pekv7jfd3sfsgdfgfdglkj%2F7E%2FlJ%2B60RnetqV2IDqrc0sVEgSLTpgTbDGU%2Ft3EcitRUFOSdOb5czt7CiIwKAYSmDEFMSNHHiNTWjvLzq4IU%2BCa4Z5aKyvww%3D%3D"}
下列「指派訊息」政策會擷取擴充功能傳回的值,並複製到回應內容中。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Storage-File-URL">
<DisplayName>Assign Storage File URL</DisplayName>
<AssignTo type="response" createNew="false"/>
<Set>
<Payload contentType="application/json">{storage.url.retrieved}</Payload>
</Set>
</AssignMessage>
動作
downloadFile
下載指定檔案。
要求參數
| 參數 | 說明 | 類型 | 預設 | 必填 |
|---|---|---|---|---|
| fileName | 要下載的檔案。 | 字串 | 無。 | 是。 |
語法
<Input><![CDATA[{"fileName" : "the-file-to-download"}]]></Input>
範例
<Input><![CDATA[{"fileName" : "example-text.txt"}]]></Input>
回應
JSON,代表含有下載檔案內容的物件。例如:
{"content":"Some example text."}
listFiles
列出可供下載的檔案。
要求參數
無。
回應
檔案名稱陣列。例如:
["example-text.txt","example-image.png"]
generateSignedURL
為值區中的指定檔案建立已簽署的網址。這個網址可用於下載檔案。
要求參數
| 參數 | 說明 | 類型 | 預設 | 必填 |
|---|---|---|---|---|
| fileName | 要產生簽署網址的 Cloud Storage 物件名稱。 | 字串 | 無。 | 是。 |
| expiresOn | 已簽署網址的到期日。 | 字串 | 無。 | 不會。 |
語法
<Input><![CDATA[{
"fileName" : "file-for-which-to-generate-url",
"expiresOn" : "date-to-expire-url"
}]]></Input>
範例
<Input><![CDATA[{
"fileName" : "example-text.txt",
"expiresOn" : "2018-08-05"
}]]></Input>
回應
代表含有已簽署網址的物件的 JSON。例如:
{"url":"https://storage.googleapis.com/storage-extension-example/example-text.txt?GoogleAccessId=extension-test%40my-test-33333.iam.gserviceaccount.com&Expires=1533427200&Signature=Y1cE1DCHesWeIZILRhdIuDR%2FhzZXZ%2BPeY3J1PUkRiosFYj41itHBWh2%2BTQgH9kI6E8s2mWrVDFU43YR7s8Tm9W5VgWRwh0nXSactQ0xKbkKbGZmCcWxgIscOezc1zc%2Bp7lnXSx1qd4wIlIKVH4KCd9WLx4qB1dLxGNxMKB32tA3dio5IiMXaHEA%2FR2fYc0Pjh45t8L5rilk5pekv7jfd3sfsgdfgfdglkj%2F7E%2FlJ%2B60RnetqV2IDqrc0sVEgSLTpgTbDGU%2Ft3EcitRUFOSdOb5czt7CiIwKAYSmDEFMSNHHiNTWjvLzq4IU%2BCa4Z5aKyvww%3D%3D"}
設定參考資料
設定及部署這個擴充功能,以便在 API Proxy 中使用時,請參考下列資訊。如要瞭解如何使用 Apigee 控制台設定擴充功能,請參閱「新增及設定擴充功能」。
常見的擴充功能屬性
每個擴充功能都有下列屬性。
| 屬性 | 說明 | 預設 | 必要 |
|---|---|---|---|
name |
您要為這項擴充功能設定的名稱。 | 無 | 相容 |
packageName |
Apigee Edge 指定的擴充功能套件名稱。 | 無 | 相容 |
version |
擴充功能的擴充功能套件版本號碼。 | 無 | 相容 |
configuration |
您要新增的擴充功能專屬的設定值。請參閱「這個擴充功能套件的屬性」一文 | 無 | 相容 |
這個擴充套件的屬性
| 屬性 | 說明 | 預設 | 必填 |
|---|---|---|---|
| bucketName | 這項擴充功能應與哪個 GCS 儲存空間互動。 | 無。 | 是。 |