Azure Blob Storage binding spec

Detailed documentation on the Azure Blob Storage binding component

Component format

To setup Azure Blob Storage binding create a component of type 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

以上示例将 Secret 明文存储。 更推荐的方式是使用 Secret 组件, here

Spec metadata fields

字段RequiredBinding supportDetailsExample
storageAccountYOutputThe Blob Storage account name“myexmapleaccount”
storageAccessKeyYOutputThe Blob Storage access key“access-key”
containerYOutputThe name of the Blob Storage container to write to“myexamplecontainer”
decodeBase64NOutputConfiguration to decode base64 file content before saving to Blob Storage. (In case of saving a file with binary content). “true” is the only allowed positive value. Other positive variations like “True” are not acceptable. Defaults to “false”“true”, “false”
getBlobRetryCountNOutputSpecifies the maximum number of HTTP GET requests that will be made while reading from a RetryReader Defaults to “10”“1”, “2”

Output bindings

This component supports output binding with the following operations:

Create blob

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

Note: by default, a random UUID is generated. See below for Metadata support to set the name

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

Examples

**Saving to a random generated UUID file**

On Windows, utilize cmd prompt (PowerShell has different escaping mechanism)

  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>

Saving to a specific file

  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>

Saving a file

To upload a file, encode it as Base64 and let the Binding know to deserialize it:

  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"

Then you can upload it as you would normally:

  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>

Response

The response body will contain the following JSON:

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

Get blob

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

  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>

#### Response The response body contains the value stored in the blob object. ## Metadata information By default the Azure Blob Storage output binding auto generates a UUID as the blob filename and is not assigned any system or custom metadata to it. It is configurable in the metadata property of the message (all optional). Applications publishing to an Azure Blob Storage output binding should send a message with the following format: ```json { “data”: “file content”, “metadata”: { “blobName” : “filename.txt”, “ContentType” : “text/plain”, “ContentMD5” : “vZGKbMRDAnMs4BIwlXaRvQ==”, “ContentEncoding” : “UTF-8”, “ContentLanguage” : “en-us”, “ContentDisposition” : “attachment”, “CacheControl” : “no-cache”, “Custom” : “hello-world”, }, “operation”: “create” } ``` ## Related links - [Basic schema for a Dapr component](https://docs.dapr.io/zh-hans/operations/components/component-schema/) - [Bindings building block](https://docs.dapr.io/zh-hans/developing-applications/building-blocks/bindings/) - [如何通过 input binding 触发应用](https://docs.dapr.io/zh-hans/developing-applications/building-blocks/bindings/howto-triggers/) - [How-To:使用绑定与外部资源进行交互](https://docs.dapr.io/zh-hans/developing-applications/building-blocks/bindings/howto-bindings/) - [绑定API 参考](https://docs.dapr.io/zh-hans/reference/api/bindings\_api/)

Last modified January 1, 0001