您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件。 資訊
版本:1.4.1
列出、下載及產生 Cloud Storage 值區中檔案的已簽署網址。
本文提供設定和使用這個擴充功能的參考資料。從 API Proxy 使用這個擴充功能前,您必須:
將物件上傳到您的值區。
授予權限以將值區存取權限授予代表 Google Cloud Storage 擴充功能的 GCP 服務帳戶。如要進一步瞭解要使用的角色,請參閱 Cloud Storage 角色。如要進一步瞭解 Cloud Storage 中的權限,請參閱使用 Identity and Access Management (IAM) 權限。
關於 Cloud Storage
Cloud Storage 是安全、耐用且可擴充的檔案儲存空間服務。如果您才剛開始使用 Cloud Storage,一開始可以參考 Cloud Storage 說明文件中的快速入門導覽課程。
範例
以下範例顯示如何使用 Extension callout 政策,為 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"]
下列 Assign Message 政策會從上述 Extension callout 政策擷取回應值,並在回應酬載中複製該值。
<?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>
下載檔案
下列擴充功能摘要政策使用 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."}
以下的「Assign Message」政策會擷取擴充功能回傳的值,並將該值複製到回應酬載。
<?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>
產生已簽署的網址
以下 Extension callout 政策會使用這個副檔名產生一個網址,以便從 Cloud Storage 值區下載指定檔案。這會傳送檔案名稱,以及網址失效日期。
<?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"}
下列的「Assign Message」政策會擷取擴充功能回傳的值,並將該值複製到回應主體中。
<?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 值區。 | 無。 | 可以。 |