I'm using the Azure.Storage.Files.DataLake nuget package to write and append file on my Azure Storage account that is enabled for Data Lake Gen2 (including hierarchy).
However, I don't seem to find how to generate a SAS-url to access a specific blob, without authenticating a user. Is it possible to have this done with the package, or should I fall back to REST operations for this?
Thanks for any insights
Seems I just had to click through to the GitHub page and there's a good example of how to do this in the Unit tests.
I copied the permalink to the specific part here: https://github.com/Azure/azure-sdk-for-net/blob/89955a90641742a2cdb0acd924f90d02b1be34ec/sdk/storage/Azure.Storage.Files.DataLake/samples/Sample02_Auth.cs#L126
AccountSasBuilder sas = new AccountSasBuilder
{
Protocol = SasProtocol.None,
Services = AccountSasServices.Blobs,
ResourceTypes = AccountSasResourceTypes.All,
StartsOn = DateTimeOffset.UtcNow.AddHours(-1),
ExpiresOn = DateTimeOffset.UtcNow.AddHours(1),
IPRange = new SasIPRange(IPAddress.None, IPAddress.None)
};
// Allow read access
sas.SetPermissions(AccountSasPermissions.List);
// Create a SharedKeyCredential that we can use to sign the SAS token
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(StorageAccountName, StorageAccountKey);
// Build a SAS URI
UriBuilder sasUri = new UriBuilder(StorageAccountBlobUri);
sasUri.Query = sas.ToSasQueryParameters(credential).ToString();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.