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. spec:
  6. type: bindings.azure.blobstorage
  7. version: v1
  8. metadata:
  9. - name: accountName
  10. value: myStorageAccountName
  11. - name: accountKey
  12. value: ***********
  13. - name: containerName
  14. value: container1
  15. # - name: decodeBase64
  16. # value: <bool>
  17. # - name: getBlobRetryCount
  18. # value: <integer>
  19. # - name: publicAccessLevel
  20. # value: <publicAccessLevel>

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

Spec metadata fields

FieldRequiredBinding supportDetailsExample
accountNameYInput/OutputThe name of the Azure Storage account“myexmapleaccount”
accountKeyY*Input/OutputThe access key of the Azure Storage account. Only required when not using Azure AD authentication.“access-key”
containerNameYOutputThe name of the Blob Storage container to write tomyexamplecontainer
endpointNInput/OutputOptional custom endpoint URL. This is useful when using the Azurite emulator or when using custom domains for Azure Storage (although this is not officially supported). The endpoint must be the full base URL, including the protocol (http:// or https://), the IP or FQDN, and optional port.http://127.0.0.1:10000
decodeBase64NOutputConfiguration to decode base64 file content before saving to Blob Storage. (In case of saving a file with binary content). Defaults to falsetrue, false
getBlobRetryCountNOutputSpecifies the maximum number of HTTP GET requests that will be made while reading from a RetryReader Defaults to 101, 2
publicAccessLevelNOutputSpecifies whether data in the container may be accessed publicly and the level of access (only used if the container is created by Dapr). Defaults to noneblob, container, none

Azure Active Directory (AAD) authentication

The Azure Blob Storage binding component supports authentication using all Azure Active Directory mechanisms. For further information and the relevant component metadata fields to provide depending on the choice of AAD authentication mechanism, see the docs for authenticating to Azure.

Binding support

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

Save text to a random generated UUID blob

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>
Save text to a specific 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>
Save a file to a blob

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. spec:
  6. type: bindings.azure.blobstorage
  7. version: v1
  8. metadata:
  9. - name: accountName
  10. value: myStorageAccountName
  11. - name: accountKey
  12. value: ***********
  13. - name: containerName
  14. value: container1
  15. - name: decodeBase64
  16. 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. "includeMetadata": "true"
  6. }
  7. }

The metadata parameters are:

  • blobName - the name of the blob
  • includeMetadata- (optional) defines if the user defined metadata should be returned or not, defaults to: false

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. If enabled, the user defined metadata will be returned as HTTP headers in the form:

Metadata.key1: value1 Metadata.key2: value2

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. }

The metadata parameters are:

  • blobName - the name of the blob
  • deleteSnapshots - (optional) required if the blob has associated snapshots. Specify one of the following two options:
    • include: Delete the base blob and all of its snapshots
    • only: Delete only the blob’s snapshots and not the blob itself

Examples

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

Response

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

List blobs

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

  1. {
  2. "operation": "list",
  3. "data": {
  4. "maxResults": 10,
  5. "prefix": "file",
  6. "marker": "2!108!MDAwMDM1IWZpbGUtMDgtMDctMjAyMS0wOS0zOC01NS03NzgtMjEudHh0ITAwMDAyOCE5OTk5LTEyLTMxVDIzOjU5OjU5Ljk5OTk5OTlaIQ--",
  7. "include": {
  8. "snapshots": false,
  9. "metadata": true,
  10. "uncommittedBlobs": false,
  11. "copy": false,
  12. "deleted": false
  13. }
  14. }
  15. }

The data parameters are:

  • maxResults - (optional) specifies the maximum number of blobs to return, including all BlobPrefix elements. If the request does not specify maxresults the server will return up to 5,000 items.
  • prefix - (optional) filters the results to return only blobs whose names begin with the specified prefix.
  • marker - (optional) a string value that identifies the portion of the list to be returned with the next list operation. The operation returns a marker value within the response body if the list returned was not complete. The marker value may then be used in a subsequent call to request the next set of list items.
  • include - (optional) Specifies one or more datasets to include in the response:
    • snapshots: Specifies that snapshots should be included in the enumeration. Snapshots are listed from oldest to newest in the response. Defaults to: false
    • metadata: Specifies that blob metadata be returned in the response. Defaults to: false
    • uncommittedBlobs: Specifies that blobs for which blocks have been uploaded, but which have not been committed using Put Block List, be included in the response. Defaults to: false
    • copy: Version 2012-02-12 and newer. Specifies that metadata related to any current or previous Copy Blob operation should be included in the response. Defaults to: false
    • deleted: Version 2017-07-29 and newer. Specifies that soft deleted blobs should be included in the response. Defaults to: false

Response

The response body contains the list of found blocks as also the following HTTP headers:

Metadata.marker: 2!108!MDAwMDM1IWZpbGUtMDgtMDctMjAyMS0wOS0zOC0zNC04NjctMTEudHh0ITAwMDAyOCE5OTk5LTEyLTMxVDIzOjU5OjU5Ljk5OTk5OTlaIQ-- Metadata.number: 10

  • marker - the next marker which can be used in a subsequent call to request the next set of list items. See the marker description on the data property of the binding input.
  • number - the number of found blobs

The list of blobs will be returned as JSON array in the following form:

  1. [
  2. {
  3. "XMLName": {
  4. "Space": "",
  5. "Local": "Blob"
  6. },
  7. "Name": "file-08-07-2021-09-38-13-776-1.txt",
  8. "Deleted": false,
  9. "Snapshot": "",
  10. "Properties": {
  11. "XMLName": {
  12. "Space": "",
  13. "Local": "Properties"
  14. },
  15. "CreationTime": "2021-07-08T07:38:16Z",
  16. "LastModified": "2021-07-08T07:38:16Z",
  17. "Etag": "0x8D941E3593C6573",
  18. "ContentLength": 1,
  19. "ContentType": "application/octet-stream",
  20. "ContentEncoding": "",
  21. "ContentLanguage": "",
  22. "ContentMD5": "xMpCOKC5I4INzFCab3WEmw==",
  23. "ContentDisposition": "",
  24. "CacheControl": "",
  25. "BlobSequenceNumber": null,
  26. "BlobType": "BlockBlob",
  27. "LeaseStatus": "unlocked",
  28. "LeaseState": "available",
  29. "LeaseDuration": "",
  30. "CopyID": null,
  31. "CopyStatus": "",
  32. "CopySource": null,
  33. "CopyProgress": null,
  34. "CopyCompletionTime": null,
  35. "CopyStatusDescription": null,
  36. "ServerEncrypted": true,
  37. "IncrementalCopy": null,
  38. "DestinationSnapshot": null,
  39. "DeletedTime": null,
  40. "RemainingRetentionDays": null,
  41. "AccessTier": "Hot",
  42. "AccessTierInferred": true,
  43. "ArchiveStatus": "",
  44. "CustomerProvidedKeySha256": null,
  45. "AccessTierChangeTime": null
  46. },
  47. "Metadata": null
  48. }
  49. ]

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:

  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. }

Last modified October 4, 2022: Updated metadata for various Azure components (#2855) (d5a8227b)