如何在 csharp 的 Azure Data Lake Gen2 中为我的 blob 文件创建 sharedaccesssignature URL
How to create a sharedaccesssignature URL for my blob file in Azure Data Lake Gen2 in csharp
我正在使用 Azure.Storage.Files.DataLake nuget 包在我的 Azure 存储帐户上写入和附加文件,该帐户已为 Data Lake Gen2(包括层次结构)启用。
但是,我似乎没有找到如何在不对用户进行身份验证的情况下生成 SAS-url 来访问特定的 blob。是否可以通过包完成此操作,或者我应该为此退回到 REST 操作?
感谢您的任何见解
似乎我只需要点击进入 GitHub 页面,在单元测试中有一个很好的例子说明如何做到这一点。
我将永久链接复制到此处的特定部分:
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();
我正在使用 Azure.Storage.Files.DataLake nuget 包在我的 Azure 存储帐户上写入和附加文件,该帐户已为 Data Lake Gen2(包括层次结构)启用。
但是,我似乎没有找到如何在不对用户进行身份验证的情况下生成 SAS-url 来访问特定的 blob。是否可以通过包完成此操作,或者我应该为此退回到 REST 操作?
感谢您的任何见解
似乎我只需要点击进入 GitHub 页面,在单元测试中有一个很好的例子说明如何做到这一点。
我将永久链接复制到此处的特定部分: 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();