user584018
user584018

Reputation: 11304

getting failed authentication error while upload blob using connection string contains both container name & sas token

I am trying to upload a blob using below code using nuget package <PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" /> where connectionString contains both container name (my-container) and SAS token,

https://my-storage.blob.core.windows.net/my-container?sv=2018-03-28&sr=c&sig=DZSbKgaKd%2FjYQbYQf7eOAZ%2BVFSY1Rq2M7HIVXs%2F%2BPtA%3D&se=2023-02-12T04%3A08%3A07Z&sp=rcwl

Code:

var blobClient = new BlobClient(new Uri(connectionString));
await using var fileStream = entry.Open();
await blobClient.UploadAsync(fileStream, true);

I am getting error,

AuthenticationFailedServer failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

RequestId:5a7b1650-501e-001d-7ed2-3d2845000000 Time:2023-02-11T04:35:40.8903035ZSignature did not match. String to sign used was rcwl

Upvotes: 0

Views: 1041

Answers (1)

Gaurav Mantri
Gaurav Mantri

Reputation: 136226

The reason your code is failing is because you're trying to create an instance of BlobClient using a container SAS URL. What you need to do is create an instance of BlobContainerClient using the SAS URL and then create an instance of BlobClient.

Please try something like:

var blobContainerClient = new BlobContainerClient(new Uri(connectionString));
var blobClient = blobContainerClient.GetBlobClient("blobname");
await using var fileStream = entry.Open();
await blobClient.UploadAsync(fileStream, true);

Upvotes: 2

Related Questions