I have the following method to get a SAS token, everything works fine.
private Uri GetUriSasToken()
{
string storedPolicyName = null;
string connectionString = _config.GetConnectionString("BlobConnection");
BlobContainerClient containerClient = new BlobContainerClient(connectionString, "stock");
// Check whether this BlobContainerClient object has been authorized with Shared Key.
if (containerClient.CanGenerateSasUri)
{
// Create a SAS token that's valid for one hour.
BlobSasBuilder sasBuilder = new BlobSasBuilder()
{
BlobContainerName = containerClient.Name,
Resource = "c"
};
if (storedPolicyName == null)
{
sasBuilder.ExpiresOn = DateTimeOffset.UtcNow.AddHours(1);
sasBuilder.SetPermissions(BlobContainerSasPermissions.Read | BlobContainerSasPermissions.List);
}
else
{
sasBuilder.Identifier = storedPolicyName;
}
Uri sasUri = containerClient.GenerateSasUri(sasBuilder);
return sasUri;
}
else
{
_logger.LogError(@"BlobContainerClient must be authorized with Shared Key credentials to create a service SAS.");
return null;
}
}
Then, I call the above method with the following code:
BlobServiceClient blobServiceClient = new BlobServiceClient(GetUriSasToken(), null);
var blobName = _config.GetValue<string>("BlobName");
var containerName = _config.GetValue<string>("ContainerName");
var fileName = _config.GetValue<string>("FileName");
var containerClient = blobServiceClient.GetBlobContainerClient(containerName);
Is there any way I can verify that the container exists?
I'm not sure I can do:
containerClient.Exists
I used it but it returns an error that the Blob does not exists, but I want to check first if the container exists.
Anyone has done this?