Azure Blob Storage绑定规范

关于 Azure Blob Storage绑定组件的详细文档

配置

要设置 Azure Blob Storage 绑定,请创建一个类型为 bindings.azure.blobstorage 的组件。 See this guide on how to create and apply a binding configuration.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: bindings.azure.blobstorage
  8. version: v1
  9. metadata:
  10. - name: storageAccount
  11. value: myStorageAccountName
  12. - name: storageAccessKey
  13. value: ***********
  14. - name: container
  15. value: container1
  16. - name: decodeBase64
  17. value: <bool>
  18. - name: getBlobRetryCount
  19. value: <integer>

Warning

以上示例将密钥明文存储, It is recommended to use a secret store for the secrets as described here.

元数据字段规范

字段必填绑定支持详情Example
storageAccountY输出Blob Storage 账户名称“myexmapleaccount”
storageAccessKeyY输出Blob Storage 访问密钥“access-key”
containerY输出要写入的Blob Storage容器名称“myexamplecontainer”
decodeBase64N输出配置在保存到Blob Storage之前对base64文件内容进行解码。 (保存有二进制内容的文件时)。 “true”是唯一允许的正值。 其他正值,如“True”是不可接受的。 默认值为 “false”“true”, “false”
getBlobRetryCountN输出指定从 RetryReader 读取时,将进行的 HTTP GET 请求的最大次数 默认为 “10”“1”, “2”

绑定支持

字段名为 ttlInSeconds

创建blob

要执行创建 blob 操作,请使用 POST 方法和以下 JSON 调用 Azure Blob Storage绑定。

注意:默认情况下,会随机生成一个UUID。 参见下面所示的支持的元数据设置名称

  1. {
  2. "operation": "create",
  3. "data": "YOUR_CONTENT"
  4. }

示例

保存到一个随机生成的UUID blob

在Windows上,使用cmd提示符(PowerShell有不同的转义机制)。

  1. curl -d "{ \"operation\": \"create\", \"data\": \"Hello World\" }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "create", "data": "Hello World" }' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
保存文本到指定blob
  1. curl -d "{ \"operation\": \"create\", \"data\": \"Hello World\", \"metadata\": { \"blobName\": \"my-test-file.txt\" } }" \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "create", "data": "Hello World", "metadata": { "blobName": "my-test-file.txt" } }' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
保存文件到blob

要上传一个文件,将其编码为Base64,并让绑定知道要对它进行反序列化:

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: bindings.azure.blobstorage
  8. version: v1
  9. metadata:
  10. - name: storageAccount
  11. value: myStorageAccountName
  12. - name: storageAccessKey
  13. value: ***********
  14. - name: container
  15. value: container1
  16. - name: decodeBase64
  17. value: "true"

然后你就可以像平常一样上传了:

  1. curl -d "{ \"operation\": \"create\", \"data\": \"YOUR_BASE_64_CONTENT\", \"metadata\": { \"blobName\": \"my-test-file.jpg\" } }" http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "create", "data": "YOUR_BASE_64_CONTENT", "metadata": { "blobName": "my-test-file.jpg" } }' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>

响应

响应体将包含以下JSON:

  1. {
  2. "blobURL": "https://<your account name>. {
  3. "blobURL": "https://<your account name>. blob.core.windows.net/<your container name>/<filename>"
  4. }

获取blob

要执行获取blob操作,请使用POST方法和以下JSON体调用Azure Blob Storage绑定:

  1. {
  2. "operation": "get",
  3. "metadata": {
  4. "blobName": "myblob"
  5. }
  6. }

Example

  1. curl -d '{ \"operation\": \"get\", \"metadata\": { \"blobName\": \"myblob\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "get", "metadata": { "blobName": "myblob" }}' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>

响应

响应体包含存储在blob对象中的值。

Delete blob

To perform a delete blob operation, invoke the Azure Blob Storage binding with a POST method and the following JSON body:

  1. {
  2. "operation": "delete",
  3. "metadata": {
  4. "blobName": "myblob"
  5. }
  6. }

示例

Delete blob
  1. curl -d '{ \"operation\": \"delete\", \"metadata\": { \"blobName\": \"myblob\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "delete", "metadata": { "blobName": "myblob" }}' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Delete blob snapshots only
  1. curl -d '{ \"operation\": \"delete\", \"metadata\": { \"blobName\": \"myblob\", \"DeleteSnapshotOptions\": \"only\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "delete", "metadata": { "blobName": "myblob", "DeleteSnapshotOptions": "only" }}' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
Delete blob including snapshots
  1. curl -d '{ \"operation\": \"delete\", \"metadata\": { \"blobName\": \"myblob\", \"DeleteSnapshotOptions\": \"include\" }}' http://localhost:<dapr-port>/v1.0/bindings/<binding-name>
  1. curl -d '{ "operation": "delete", "metadata": { "blobName": "myblob", "DeleteSnapshotOptions": "include" }}' \
  2. http://localhost:<dapr-port>/v1.0/bindings/<binding-name>

响应

An HTTP 204 (No Content) and empty body will be retuned if successful.

元数据信息

默认情况下,Azure Blob Storage 输出绑定会自动生成一个 UUID 作为 blob 文件名,并且不会为其分配任何系统或自定义元数据。 它可以在消息的元数据属性中配置(都是可选的)。

应用程序发布到 Azure Blob Storage 输出绑定时,应发送格式如下的消息。

  1. {
  2. "data": "file content",
  3. "metadata": {
  4. "blobName" : "filename.txt",
  5. "ContentType" : "text/plain",
  6. "ContentMD5" : "vZGKbMRDAnMs4BIwlXaRvQ==",
  7. "ContentEncoding" : "UTF-8",
  8. "ContentLanguage" : "en-us",
  9. "ContentDisposition" : "attachment",
  10. "CacheControl" : "no-cache",
  11. "Custom" : "hello-world",
  12. },
  13. "operation": "create"
  14. }

相关链接