|
| 1 | +--- |
| 2 | +title: "Blob storage" |
| 3 | +description: Get started with Blob storage on LocalStack |
| 4 | +template: doc |
| 5 | +--- |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +Azure Blob storage is a service for storing large amounts of unstructured data, such as text or binary data. |
| 10 | +Blob storage is used to serve images or documents directly to a browser, storing files for distributed access, streaming video and audio, and writing to log files. |
| 11 | + |
| 12 | +LocalStack for Azure allows you to use Blob storage APIs in your local environment to upload and download blobs, and manage containers. |
| 13 | + |
| 14 | +## Getting started |
| 15 | + |
| 16 | +This guide is designed for users who are new to Blob storage and assumes that [`azlocal` is installed](/azure/getting-started/). |
| 17 | +We will demonstrate how to create a resource group, storage account, container, upload and download blobs, and view blob details. |
| 18 | + |
| 19 | +### Create a resource group |
| 20 | + |
| 21 | +You can create a resource group using the following command: |
| 22 | + |
| 23 | +``` |
| 24 | +$ az group create \ |
| 25 | + --name MyResourceGroup \ |
| 26 | + --location westeurope |
| 27 | +``` |
| 28 | + |
| 29 | +The following output would be displayed: |
| 30 | + |
| 31 | +```bash |
| 32 | +{ |
| 33 | + "id": "/subscriptions/some-generated-id/resourceGroups/MyResourceGroup", |
| 34 | + "location": "westeurope", |
| 35 | + "managedBy": null, |
| 36 | + "name": "MyResourceGroup", |
| 37 | + "properties": { |
| 38 | + "provisioningState": "Succeeded" |
| 39 | + }, |
| 40 | + "tags": null, |
| 41 | + "type": "Microsoft.Resources/resourceGroups" |
| 42 | +} |
| 43 | +``` |
| 44 | + |
| 45 | +### Create a storage account |
| 46 | + |
| 47 | +You can create a storage account using the following command: |
| 48 | + |
| 49 | +``` |
| 50 | +$ az storage account create \ |
| 51 | + --name testaccount \ |
| 52 | + --resource-group MyResourceGroup \ |
| 53 | + --location westeurope \ |
| 54 | + --sku Standard_LRS |
| 55 | +``` |
| 56 | + |
| 57 | +The following output would be displayed: |
| 58 | + |
| 59 | +```bash |
| 60 | +{ |
| 61 | + ... |
| 62 | + "id": "/subscriptions/some-generated-id/resourceGroups/MyResourceGroup/providers/Microsoft.Storage/storageAccounts/testaccount", |
| 63 | + ... |
| 64 | + "primaryEndpoints": { |
| 65 | + "blob": "https://testaccountblob.localhost.localstack.cloud:4566", |
| 66 | + "dfs": "https://testaccount.dfs.core.windows.net/", |
| 67 | + "file": "https://testaccount.file.core.windows.net/", |
| 68 | + "internetEndpoints": null, |
| 69 | + "microsoftEndpoints": null, |
| 70 | + "queue": "https://testaccountqueue.localhost.localstack.cloud:4566", |
| 71 | + "table": "https://testaccounttable.localhost.localstack.cloud:4566", |
| 72 | + "web": "https://testaccount.z28.web.core.windows.net/" |
| 73 | + }, |
| 74 | + ... |
| 75 | + "sku": { |
| 76 | + "name": "Standard_LRS", |
| 77 | + "tier": "Standard" |
| 78 | + }, |
| 79 | + ... |
| 80 | + "type": "Microsoft.Storage/storageAccounts" |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +### Create a container |
| 85 | + |
| 86 | +You can create a container using the following command: |
| 87 | + |
| 88 | +``` |
| 89 | +$ azlocal storage container create \ |
| 90 | + --name testcontainer \ |
| 91 | + --account-name testaccount \ |
| 92 | + --auth-mode login |
| 93 | +``` |
| 94 | + |
| 95 | +Note the use of `azlocal` here! |
| 96 | + |
| 97 | +There are certain commands, like `az storage container`, that do not properly work with the Emulator. They do work if you use the `azlocal` tool instead. |
| 98 | + |
| 99 | +The following output would be displayed: |
| 100 | + |
| 101 | +```bash |
| 102 | +{ |
| 103 | + "created": true |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +You can list the containers using the following command: |
| 108 | + |
| 109 | +``` |
| 110 | +$ azlocal storage container list \ |
| 111 | + --account-name testaccount \ |
| 112 | + --auth-mode login |
| 113 | +``` |
| 114 | + |
| 115 | +The following output would be displayed: |
| 116 | + |
| 117 | +```bash |
| 118 | +[ |
| 119 | + { |
| 120 | + "deleted": null, |
| 121 | + ... |
| 122 | + "immutableStorageWithVersioningEnabled": false, |
| 123 | + "metadata": null, |
| 124 | + "name": "testcontainer", |
| 125 | + "properties": { |
| 126 | + "etag": null, |
| 127 | + "hasImmutabilityPolicy": false, |
| 128 | + ... |
| 129 | + "publicAccess": null |
| 130 | + }, |
| 131 | + "version": null |
| 132 | + } |
| 133 | +] |
| 134 | +``` |
| 135 | + |
| 136 | +### Upload and download blobs |
| 137 | + |
| 138 | +You can upload a blob using the following command: |
| 139 | + |
| 140 | +``` |
| 141 | +$ azlocal storage blob upload \ |
| 142 | + --container-name testcontainer \ |
| 143 | + --account-name testaccount \ |
| 144 | + --data "Your raw data here" \ |
| 145 | + --name testblog \ |
| 146 | + --auth-mode login |
| 147 | +``` |
| 148 | + |
| 149 | +The following output would be displayed: |
| 150 | + |
| 151 | +```bash |
| 152 | +Alive[################################################Finished[#############################################################] 100.0000% |
| 153 | +{ |
| 154 | + "client_request_id": null, |
| 155 | + ... |
| 156 | + "encryption_key_sha256": null, |
| 157 | + "encryption_scope": null, |
| 158 | + ... |
| 159 | + "version": null, |
| 160 | + "version_id": null |
| 161 | +} |
| 162 | +``` |
| 163 | +
|
| 164 | +You can download a blob using the following command: |
| 165 | +
|
| 166 | +``` |
| 167 | +$ azlocal storage blob download \ |
| 168 | + --container-name testcontainer \ |
| 169 | + --account-name testaccount \ |
| 170 | + --file check.txt \ |
| 171 | + --name testblog \ |
| 172 | + --auth-mode login |
| 173 | +``` |
| 174 | +
|
| 175 | +You can inspect the downloaded file `check.txt` to verify the contents. |
| 176 | +
|
| 177 | +### View blob details |
| 178 | +
|
| 179 | +You can view blob details using the following command: |
| 180 | +
|
| 181 | +``` |
| 182 | +$ azlocal storage blob show \ |
| 183 | + --account-name testaccount \ |
| 184 | + --container testcontainer \ |
| 185 | + --auth-mode login \ |
| 186 | + --name testblog |
| 187 | +``` |
| 188 | +
|
| 189 | +The following output would be displayed: |
| 190 | +
|
| 191 | +```bash |
| 192 | +Alive[################################################Finished[#############################################################] 100.0000% |
| 193 | +{ |
| 194 | + "container": "testcontainer", |
| 195 | + ... |
| 196 | + "name": "testblog", |
| 197 | + "objectReplicationDestinationPolicy": null, |
| 198 | + "objectReplicationSourceProperties": [], |
| 199 | + ... |
| 200 | + "rehydratePriority": null, |
| 201 | + "requestServerEncrypted": null, |
| 202 | + "snapshot": null, |
| 203 | + ... |
| 204 | + "versionId": null |
| 205 | +} |
| 206 | +``` |
0 commit comments