How to download/upload files from a given Azure SASUri link

Brandon Ho 376 Reputation points
2021-03-19T18:29:38.523+00:00

Hi,
I have been given a SASUri link to develop a console app to upload/download files from Azure blob. I can attach the SASUri link from Azure Storage Explorer and see the files.

SASUri - https://STORAGEACCOUNT.blob.core.windows.net/testcontainer?sv=2020-04-08&si=test-read&sr=c&sig=SIGNATURE

When I use the code below to call the link, I received the error. Does anyone have a sample to upload/download files from a given SASUri link?

            BlobClient blobClient = new BlobClient(new Uri("https://STORAGEACCOUNT.blob.core.windows.net/testcontainer?sv=2020-04-08&si=test-read&sr=c&sig=SIGNATURE"));
           Azure.Response<BlobDownloadInfo> response = blobClient.Download();

Azure.RequestFailedException
HResult=0x80131500
Message=Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:c08759e2-f01e-006e-6deb-1cb6b6000000
Time:2021-03-19T18:14:19.6133856Z
Status: 403 (Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.)
ErrorCode: AuthenticationFailed

Additional Information:
AuthenticationErrorDetail: Signature did not match. String to sign used was

/blob/STORAGEACCOUNT/$root
test-read

2020-04-08
c

Headers:
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: c08759e2-f01e-006e-6deb-1cb6b6000000
x-ms-error-code: AuthenticationFailed
Date: Fri, 19 Mar 2021 18:14:19 GMT
Content-Length: 481
Content-Type: application/xml

Source=Azure.Storage.Blobs
StackTrace:
at Azure.Storage.Blobs.BlobRestClient.Blob.DownloadAsync_CreateResponse(ClientDiagnostics clientDiagnostics, Response response)
at Azure.Storage.Blobs.BlobRestClient.Blob.<DownloadAsync>d__0.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Threading.Tasks.ValueTask1.get_Result() at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable1.ConfiguredValueTaskAwaiter.GetResult()
at Azure.Storage.Blobs.Specialized.BlobBaseClient.<StartDownloadAsync>d__61.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable1.ConfiguredTaskAwaiter.GetResult() at Azure.Storage.Blobs.Specialized.BlobBaseClient.<DownloadInternal>d__60.MoveNext() at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at Azure.Core.Pipeline.TaskExtensions.EnsureCompletedT
at Azure.Storage.Blobs.Specialized.BlobBaseClient.Download(HttpRange range, BlobRequestConditions conditions, Boolean rangeGetContentHash, CancellationToken cancellationToken)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.Download(CancellationToken cancellationToken)
at Azure.Storage.Blobs.Specialized.BlobBaseClient.Download()
at AzureApp.Program.<Main>g__GetAccountContainerAndBlobNameFromUrl|0_0() in C:\Brian\AzureApp\Program.cs:line 25
at AzureApp.Program.Main(String[] args) in C:\Brian\AzureApp\Program.cs:line 18

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,427 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 33,456 Reputation points Microsoft Employee
    2021-03-19T21:22:18.303+00:00

    @Brandon Ho
    Sample code for downloading blobs with a SAS URI can be found here. You can also see example code here of authenticating with the SAS URI.

    Please try these out and let us know if they work for you. You might also consider posting over on Stack Overflow so our developer experts can assist.

    -------------------------------

    Please don’t 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