I'm currently generating SAS tokens using the Microsoft.WindowsAzure.Storage.CloudStorageAccount
class like so:
var cloudStorageAccount = // create a new CloudStorageAccount
var sharedAccessAccountPolicy = new SharedAccessAccountPolicy
{
Permissions = SharedAccessAccountPermissions.Read | SharedAccessAccountPermissions.Write,
Services = SharedAccessAccountServices.Blob,
ResourceTypes = SharedAccessAccountResourceTypes.Object,
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),
Protocols = SharedAccessProtocol.HttpsOnly
};
var token = cloudStorageAccount.GetSharedAccessSignature(sharedAccessAccountPolicy);
However, this returns a token with a ?
in front and does not include the blob endpoint. I was looking at this documentation and noticed a SAS looks like below:
BlobEndpoint=https://storagesample.blob.core.windows.net;
SharedAccessSignature=sv=2015-04-05&sr=b&si=tutorial-policy-635959936145100803&sig=9aCzs76n0E7y5BpEi2GvsSv433BZa22leDOZXX%2BXXIU%3D
What's neat about this is that I can use it as a connection string to directly initialize a BlockBlobClient
.
How can I generate my token in the above format? I can parse my own and remove the ?
and then add the BlobEndpoint
and SharedAccessSignature
keys, but this is manual work and may not function properly in the future. Is there an SDK method that creates a SAS in the format that's shown on Microsoft's documentation?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…