Access Azure Blob Storage from Linux VM

James Lux 26 Reputation points
2024-05-13T19:13:47.31+00:00

I am trying to copy files from an Azure Blob to a Linux VM on the same Subscription & Resource Group using CURL. I am able to get a token from Azure using this URL.

http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fstorage.azure.com%2F' -H Metadata:true

I am then able to get a SAS token using this URL.

https://management.azure.com/subscriptions/$substription/resourceGroups/$resourceGroup/providers/Microsoft.Storage/storageAccounts/$storageAccount/listServiceSas/?api-version=2017-06-01

Once I have the SAS token, I am unable to use any Microsoft published REST call with CURL to list or copy files.

Has anyone done this?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,291 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,493 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Luis Arias 5,136 Reputation points
    2024-05-13T20:38:17.88+00:00

    Hi James Lux,

    Yes, it’s possible to perform operations on Azure Blob Storage using CURL. Here are some examples of how you can list and put blobs using CURL:

    List Blobs

    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 this command, replace <HTTP Verb> with GET, storageAccountName with your storage account name, containerName with the name of your container, and SASToken with your SAS token1.

    Put Blob

    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 this command, replace <HTTP Verb> with PUT, storageAccountName with your storage account name, containerName with the name of your container, blobname with the name of your blob, and SASToken with your SAS token1. Also, replace <Date and Time in GMT format>, Blob Type, and <Length of the blob> with the appropriate values1.

    Reference:

    If the information helped address your question, please Accept the answer.

    Luis

    0 comments No comments

  2. Anand Prakash Yadav 6,785 Reputation points Microsoft Vendor
    2024-05-14T05:31:49.6066667+00:00

    Hello James Lux,

    Thank you for posting your query here!

    It seems like you’re having trouble using the SAS token to list or copy files from an Azure Blob to a Linux VM. Here’s a general example of how you can use curl with a SAS token to list blobs in a container:

    curl -X GET "https://[your-account-name].blob.core.windows.net/[your-container-name]?restype=container&comp=list&[your-SAS-token]"
    
    

    And here’s how you can download a blob:

    curl -X GET "https://[your-account-name].blob.core.windows.net/[your-container-name]/[your-blob-name]?[your-SAS-token]" --output [your-local-file]
    
    

    Please replace [your-account-name][your-container-name][your-SAS-token][your-blob-name], and [your-local-file] with your actual values.

    If you’re still having trouble, could you please provide the exact error message you’re seeing? That would help us better understand the issue. Remember to redact any sensitive information from the error message before sharing it.

    Do let us know if you have any further queries. I’m happy to assist you further.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments