Loading...

Performing simple BLOB Storage REST API operations using CURL

Performing simple BLOB Storage REST API operations using CURL

The blog points to perform simple storage REST API operations such as Get, Put, List and Delete using CURL utility.

 

Let’s look at some of the CURL command syntax to perform REST API operations and will be making use of SAS as the auth scheme.  We need to take care of the pointers below while performing the operations via CURL:

 

  • Ensure the URL is formed correctly as per the operation you are trying to perform.
  • The mandatory header needs to be passed and can be done using “-H” parameter.
  • Ensure you are appending/removing extra ‘?’ to the SAS token in the URLs accordingly.
  • Http verb can be GET, PUT or DELETE as provided by the CURL specifications.

List Blobs

List Blobs (REST API) - Azure Storage | Microsoft Docs

 

Syntax:

curl -I -X <HTTP Verb> -H "x-ms-version: 2019-12-12" “https://storageAccountName.blob.core.windows.net/containerName?restype=container&comp=list&SASToken

 

In the below snippet, the operation is being performed over a container named testcontainer11. There is just one single blob present in the container, and it is listed as below:

Amrinder_Singh_0-1651678550828.png

Put Blob

Put Blob (REST API) - Azure Storage | Microsoft Docs

 

Syntax:

curl -i -X <HTTP Verb> -H "x-ms-version: 2019-12-12" -H "x-ms-date: <Date and Time in GMT format>" -H "x-ms-blob-type: Blob Type" -H "Content-Length: <Length of the blob>" -d "Blob data/content" “https://storageAccountName.blob.core.windows.net/containerName/blobname?SASToken

 

In the below snippet example, a Put operation was performed over the container named testcontainer11 and the blob name is myblob3. The blob type was passed as block blob along with the content of the blob and its length. The blob was created successfully.

 

Amrinder_Singh_2-1651678625144.png

You could further validate using Azure Portal or Azure Storage explorer as per your feasibility.

Amrinder_Singh_3-1651678657612.png

The above example was inclined towards the Block Blob however we can also perform the same over the append blobs as well. Below is how we need to perform the same:

 

We first need to call the Put Blob operation only with blob type as Append Blob and with Content-Length header as 0

curl -i -X <HTTP Verb> -H "x-ms-version: 2019-12-12" -H "x-ms-date: <Date and Time in GMT format>" -H "x-ms-blob-type: AppendBlob" -H "Content-Length: 0"  “https://storageAccountName.blob.core.windows.net/containerName/blobname?SASToken

 

Amrinder_Singh_4-1651678703106.png

Amrinder_Singh_6-1651678715453.png

We then call the Append Block API to write to the blob

Append Block (REST API) - Azure Storage | Microsoft Docs

 

curl -i -X <HTTP Verb> -H "x-ms-version: 2019-12-12" -H "x-ms-date: <Date and Time in GMT format>" -H "Content-Length: Content Length in Bytes" -d "Content of the blob"  "https://storageAccountName.blob.core.windows.net/containerName/blobname?comp=appendblock&SASToken"

Amrinder_Singh_7-1651678735504.png

Amrinder_Singh_9-1651678748001.png

At this point, below were the content of the file:

Amrinder_Singh_10-1651678772660.png

We again called the Append Block API to append to the above blob further as well.

Amrinder_Singh_11-1651678791092.png

You will notice a change in the file size

Amrinder_Singh_12-1651678806616.png

We could see updated content as well:

Amrinder_Singh_13-1651678813275.png

 

Get Blob

Get Blob (REST API) - Azure Storage | Microsoft Docs

 

Syntax:

curl -i -X <HTTP Verb> -H "x-ms-version: 2019-12-12" "https://storageAccountName.blob.core.windows.net/containername/blobname?SASToken"

 

In the below example, we tried performing the GetBlob operation on the same blob name myblob3 present in the container named testcontainer11 that we created as part of above Put Operation

Amrinder_Singh_14-1651678832414.png

 

Delete Blob

Delete Blob (REST API) - Azure Storage | Microsoft Docs

 

Syntax:

curl -i -X <HTTP Verb> -H "x-ms-version: 2019-12-12" “https://storageAccountName.blob.core.windows.net/containername/blobname?SASToken

 

In the below example snippet, we deleted the blob named myblob3 from the container named testcontainer11

Amrinder_Singh_15-1651678832422.png

 

Amrinder_Singh_16-1651678832432.png

 

Copy Blob

Copy Blob (REST API) - Azure Storage | Microsoft Docs

 

Syntax:

curl --request <http Verb> "<Destination URL>" --header "x-ms-date: <Date and Time in GMT format>" " --header "x-ms-version: 2019-12-12" --header "x-ms-copy-source: <SOURCE URL>" --header "Content-length: 0"

 

In the below example snippet, we copied the blob named Appointment_confirmation.jpg from the container named testcontainer10 present in the source storage account to a blob named abc.jpg present in destination container named testcontainer present in the destination storage account

Amrinder_Singh_17-1651678832439.png

Hope this helps!

 

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy