Azure blob storage - upload blob using REST API and bearer token in Postman

Suraj SomaniSuraj Somani
2 min read

In this blog, we will see steps on how to create an authorization header using bearer token created for an Azure storage account resource and call PUT blob REST API to upload a file using Postman. We will provide the required permission to perform this operation by assigning specific role to client app (RBAC). Check the official documentation of PUT blob for more details.

Pre-requisites-

  1. An Azure storage account with a container should be created.

  2. Register one app in Azure AD and get the client id and client secret for the same. This app will be used to assign RBAC and get bearer token.

Steps-

  1. To allow blob upload operation, we need to assign an app with the minimum privileged role required- Azure Blob Data Contributor.

  2. Follow this blog and get access token for storage account i.e. use resource parameter value as- https://storage.azure.com in get token request.

  3. Create a new PUT request "Azure blob storage- RBAC- upload file" with the below url.

    https://{{azure_storage_account}}.blob.core.windows.net/<container_name>/<filePath>

    It will look something like the below-

    In this url, satstorageacc1 is the storage account name, test is the name of my container and newFolder/new1.txt is the file path where I want to upload my file.

  4. Go to the request body tab, select raw, format as text and add some file content that you want to upload.

    If you want to upload a file then instead of raw, select binary and you will be able to browse file and select as body.

  5. Go to the Authorization tab and type as bearer token. Copy and paste token retrieved in step 2 as below.

  6. Go to the request header tab and add the below headers. Content-Length is a mandatory header parameter but Postman will automatically add it, so no need to add it explicitly.

  7. The request setup is ready to upload a file. Hit send button on request and you will get 201 created response as below. You can go to blob container and verify that new1.txt is created.

Conclusion- In this blog, we understood how to perform blob storage API operations by using bearer token and RBAC.

Thanks for reading.

Keep learning!

0
Subscribe to my newsletter

Read articles from Suraj Somani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suraj Somani
Suraj Somani

I am 10+ years experienced IT professional having expertise in various Azure technologies. I am certified Azure Developer & Azure Data Engineer, having vast experience in building cloud solutions.