Azure Blob storage is a service for storing large amounts of data in binary format as data chunks that can be accessed via HTTP or HTTPS. One of the finest features of the Azure blob storage is the ability to create snapshots of a blob file. The snapshot allows you to preserve the blob as of a specific point in time. Read this article to learn how to create and manage append blob with Azure Storage Rest Api.
For more such articles visit: https://www.rapidvaluesolutions.com/tech_blog/
Creating and Managing Append Blob with Azure Storage Rest API
1. [Type the document title]
Creating and Managing Append Blob with Azure Storage REST API
2. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 2
Steps to Create Append Blob with Azure Storage REST API
STEP 1 — Setup Azure Storage
1. Login to your azure subscription and select a resource group for storage.
Alternately create a new resource group.
2. Create a new storage account with type Blob Storage
We have named our storage account as ―myappendblobstore‖. Choose Replication
option as required. We have chosen LRS as we don’t need multi-region redundancy for
this exercise.
3. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 3
3. Click on Review+Create and then Click on Create
This creates the Blob Storage. The next step is to create a Container in the storage and
setup Security Access Keys
4. Click on the storage account — myappendblobstore. This will open the storage
configuration screen.
4. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 4
We have created a new container, myappendblobcontainer.
5. Click on Containers in the left menu
6. Add new Container with a chosen name and encryption scope. We have created a
new container myappendblobcontainer
7. Next Click on Access Keys in left menu and note down the Key1. This iwll be needed
for building authorization signature later.
8. If you want to provide a temporary access, use the Shared Access Signature (SAS)
option and generate a new signature and note down the three strings. SAS can be used
instead of Access Key based signature for a time bound access.
5. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 5
STEP 2 — Create New Append Blob
As mentioned earlier, an append blob needs to be created as an empty blob and
contents can be added block by block. It involves two operations — Create Blob and
Append Block. The Azure Storage REST API supports both the operations.
Prepare the PUT request for creating new append blob.
URL : The syntax of http URL is:
<storageaccountname>.blob.core.windows.net/<container>/<blobname>
6. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 6
The <blobname> shouldn’t be an existing blob. Example —
https://myappendblobstore.blob.core.windows.net/myappendblobcontaiter/appendblob0
1
HEADER: The header elements that need to be taken care of the most are x-ms-
date and Authorization. The Authorization key needs to be built using the prescribed
approach. x-ms-date value in header and x-ms-date value used in
generating Authorization must be same. Also needs to ensure the date format which
is YYYY–MM–DDThh:mm:ssZ (example-2020–12–11T05:44:35Z). The x-ms-
date should also be recent, as azure doesn't allow old timed request.
Refer to https://docs.microsoft.com/en-us/rest/api/storageservices/put-blob#request for details of request
headers
Content-Length should be 0 (zero) as the body of request is empty. Value of x-ms-blob-
type should be AppendBlob. The request body should be none or empty.
7. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 7
Generating Authorization String: Directly using the Access Key from Azure Portal, as
the Authorization will result in 403 error. The format of Authorization is:
Authorization=”[SharedKey|SharedKeyLite] [AccountName]:[Signature]”
Signature string here is to be generated programmatically using the algorithm as
suggested by Azure. The input elements to the algorithm are Access Key, Storage
Account Name, x-ms-date. The output is HMAC-SHA256 encoded Signature string.
Read this article about creating the signature, specifically for
storage: https://docs.microsoft.com/en-us/azure/storage/common/storage-rest-api-
auth#creating-the-authorization-header
Authorizing with SAS: Alternative to the Key based authorization method, we can use
the SAS based authorization as well. The SAS based token, however, is time bound and
can used to limited time access only. The SA based request would look like below
Create Append Blob Request with SAS based Authorization
RESPONSE: A successful request will return a 201 response, which indicates that the
new append blob is created successfully.
8. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 8
A successful 201 response
VERIFY: Once we get a successful response, we can verify the newly created blob in
Azure Portal. Notice that the new append blob will be of zero byte size as it is empty at
creation.
A newly created Append Blob
STEP 3 — Append Contents to Blob
To add a new block of data to the end of an existing append blob, we need to
execute Append Block operation on the blob. The Azure Storage REST API supports the
operation.
9. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 9
REQUEST: Following is the syntax of the PUT request URL for append operation.
Notice the additional http parameter comp. The blob name should be an existing blob.
https://myappendblobstore.blob.core.windows.net/myappendblobcontaiter/appendblob01
?comp=appendblock
The complete Append BlockAPI request looks as in screenshots below. We have
captured Params, Headers and Body of the request to provide a complete view for
everyone who is trying this first time.
Snapshot of Header Section of Append Block Request
Notice the highlighted section of header parameters. This request uses SAS authorization. There will be
additional headers for Access Key based authorization.
10. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 10
Snapshot of Parameters Section of Append Block Request
Notice the highlighted parameters. This request uses SAS authorization. The parameters will be different
for Access Key based authorization.
RESPONSE A successful request will return a 201 response, which indicates that the
new bloc of data appended to the end of blob successfully.
VERIFY Now that we have a successful response, let’s verify the blob in Azure Portal.
Notice the size of our blob (which was zero) it has increased which indicates the new
data has been appended.
Let’s execute the Append Block operation again to append another block.
11. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 11
Verify the blob in Azure Portal and notice the size of our blob has further increased which
indicates another data block has been appended.
Azure Blob storage is a service for storing large amounts of data in binary format as
data chunks that can be accessed via HTTP or HTTPS. One of the finest features of the
Azure blob storage is the ability to create snapshots of a blob file. The snapshot allows
you to preserve the blob as of a specific point in time.
Please refer to https://docs.microsoft.com/en-us/rest/api/storageservices for more details
on the API and operations. Happy Coding!
By,
Shahjahan Tapadar, Principal Architect, RapidValue
About
12. Creating and Managing Append Blob with Azure Storage REST API
RapidValue Solutions Page 12
About RapidValue
RapidValue is a global leader in digital product engineering solutions including
mobility, omnichannel, IoT, AI, RPA and cloud to enterprises worldwide.
RapidValue offers its digital services to the world’s top brands, Fortune 1000
companies and innovative emerging start-ups. With offices in the United States,
the United Kingdom, Germany and India and operations spread across the
Middle-East, Europe and Canada, RapidValue delivers enterprise services and
solutions across various industry verticals.
Disclaimer:
This document contains information that is confidential and proprietary to RapidValue Solutions
Inc. No part of it may be used, circulated, quoted, or reproduced for distribution outside
RapidValue. If you are not the intended recipient of this report, you are hereby notified that the
use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful.
www.rapidvaluesolutions.com/blog
+1 877.643.1850 contactus@rapidvaluesolutions.com
www.rapidvaluesolutions.com