question

BrandonHo-7950 avatar image
0 Votes"
BrandonHo-7950 asked ·

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

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.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.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.ConfiguredTaskAwaitable`1.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.TaskAwaiter`1.GetResult()
at Azure.Core.Pipeline.TaskExtensions.EnsureCompleted[T](Task`1 task)
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
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

deherman-MSFT avatar image
0 Votes"
deherman-MSFT answered ·

@BrandonHo-7950
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.

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.