1

I'm trying to create an Sas Url for a blob through a web api but i keep getting this error. I've used this blog post as a reference but changed some things i don't need. (I've tried doing exactly as the post says, copy pasted, still doesn't work)

this is my code:

var container = _blobServiceClient.GetBlobContainerClient("Files");
var client = container.GetBlobClient("dev-test/test-json.txt");
// I've tried to use just the name of the blob without the file extension and that doesn't work either

if (!client.CanGenerateSasUri)
   return string.Empty;

var builder = new BlobSasBuilder
     {
         BlobContainerName = container.Name,
         BlobName = client.Name,
         Resource = "b",
         StartsOn = DateTime.UtcNow,
         ExpiresOn = DateTime.UtcNow.AddDays(1),
         Protocol = SasProtocol.Https
     };

builder.SetPermissions(BlobSasPermissions.Read);

Uri sasUri = client.GenerateSasUri(builder);
string url = sasUri.ToString();
return await Task.FromResult(url);

i get a url that seems to be fine according to examples I've seen but when i try to access that url i get the error mentioned in the title.

when i use Generate SAS inside the azure container itself, it's working fine. but through my code it doesn't.

this is the token i get from the azure blob when i click Generate SAS:

sp=r&st=2022-06-12T21:00:00Z&se=2022-06-13T21:00:00Z&spr=https&sv=2021-06-08&sr=b&sig=2RhYyiWMGQxzidNQgsVFaiNJRDhRCKmHkQRnHM3x7J8%3D

this is the token i get through the api request:

sv=2021-06-08&spr=https&st=2022-06-13T11%3A13%3A56Z&se=2022-06-14T11%3A13%3A56Z&sr=b&sp=r&sig=1Ttgdeti6NC8vcINmCNBQL7ejdE0ajNHhJRGAdGNANg%3D
3
  • What’s the name of your container and blob? Commented Jun 13, 2022 at 11:34
  • container name is Files and the blob is in dev-test folder and the file name is test-json Commented Jun 13, 2022 at 11:37
  • Ok, through your question i realized what the problem was. the container name should be lower case as well. Thanks for you help! Commented Jun 13, 2022 at 11:41

1 Answer 1

2

Container name should be lowercase as well

var container = _blobServiceClient.GetBlobContainerClient("files");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.