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