Azure Blob Storage
Azure Blob Storage is used to store arbitrary unstructured data like images, files, backups, etc. Aidbox offers integration with Blob Storage to simplify upload and retrieval of data. You can read more on Blob Storage internals here. All examples from this tutorial are executable in Aidbox REST console.

Set up Azure storage account

First of all, we have to create AzureAccount resource with id = account name and key = secret key of your account. Your account name and keys can be found under "Access keys" section in Azure Storage account settings.
Request

Parameters

  • id (required): Azure storage Account name
  • key (required): Azure storage Account key

Example

1
POST /AzureAccount
2
3
id: aidbox
4
key: long-base64-endoded-string
Copied!

Register AzureContainer

Go to Azure console and create container, for example, "avatars". Now we can create an AzureContainer resource:
Request

Parameters

  • id (optional): id to reference this container in Aidbox requests
  • account (required): reference to AzureAccount resource
  • storage (required): Azure resource group name
  • container (required): Azure container name

Example

1
POST /AzureContainer
2
3
id: avatars
4
account: {id: aidbox, resourceType: AzureAccount}
5
storage: aidbox
6
container: avatars
Copied!

Get Shared Access Signature (SAS) to upload file

When configuration is complete, you can request a temporary URL to upload blobs. By default, such URL expires in 30 minutes. You can provide a blob name or just the extension (name will be generated).
Request
Response

Body parameters

  • blob (required): file name
  • timeout (optional, default: 30): timeout in minutes

Example

1
POST /azure/storage/avatars
2
3
blob: pt-1.png
Copied!

Body

  • url: signed url to upload file

Example

1
url: https://aidbox.blob.core.windows.net/avatars/pt-1.png?sr=signature
Copied!
Configure CORS in azure if you want to send data from browser:
Now you can upload file from your UI using signed URL provided by Aidbox:
1
//onChange input[type=file]
2
var file = inputEvent.file.originFileObj;
3
fetch("<signed-url>", {
4
method: 'PUT',
5
body: file,
6
headers: {'x-ms-blob-type': 'BlockBlob'}
7
}).then(...)
Copied!

Get SAS to read file

To read uploaded file you can request signed url with:
1
GET /azure/storage/avatar/pt-1.png
2
3
---
4
status: 200
5
url: <read-signed-url>
6
7
# or
8
9
GET /azure/storage/avatar/pt-1.png?redirect=true
10
11
---
12
status: 302
13
headers:
14
Locaiton: <read-signed-url>
Copied!
For example, you can use a trick with redirect to render image:
1
<img src="/azure/storage/avatar/pt-1.png?redirect=true"/>
Copied!