[英]Shared Access moving from windowsazure.storage to Azure.Storage.Files
For the life of me, can not get how to set a shared access file policy in the new sdk.对于我的生活,无法获得如何在新 sdk 中设置共享访问文件策略。 after uploading using the ShareFileClient i need to generate a url for another unauthenticated client to download.
使用 ShareFileClient 上传后,我需要生成一个 url 供另一个未经身份验证的客户端下载。 with the old sdk i did something like
使用旧的 sdk 我做了类似的事情
var sasConstraints = new SharedAccessFilePolicy() {
SharedAccessStartTime = DateTime.UtcNow.AddMinutes(-5) ,
SharedAccessExpiryTime = DateTime.UtcNow.AddDays(10) ,
Permissions = SharedAccessFilePermissions.Read | SharedAccessFilePermissions.List };
return myCloudFile.Uri + myCloudFile.GetSharedAccessSignature(sasConstraints);
Any and all pointers to accomplish this in the new sdk is greatly appreciated.非常感谢在新 sdk 中完成此操作的任何和所有指针。
According to my understanding, you want to a sas token for Azure File share with new Azure file sahre sdk.根据我的理解,您希望使用新的 Azure 文件 sahre sdk 共享 Azure 文件的 sas 令牌。 Regarding how to create it, please refer to the following code
关于如何创建,请参考以下代码
dotnet add package Azure.Storage.Files.Shares
# create sas token
string accountname = "<account name>";
string key = "<storage ket>";
var creds = new StorageSharedKeyCredential(accountname, key);
var builder = new ShareSasBuilder
{
ShareName = "file share name",
Protocol = SasProtocol.None,
StartsOn = DateTimeOffset.UtcNow.AddHours(-1),
ExpiresOn = DateTimeOffset.UtcNow.AddHours(+1)
};
builder.SetPermissions(ShareSasPermissions.All);
var sas = builder.ToSasQueryParameters(creds).ToString();
// test (Upload file)
// Get a reference to a share
ShareClient share = new ShareClient(connectionString, shareName);
// Get a reference to a directory and create it
ShareDirectoryClient directory = share.GetDirectoryClient(dirName);
directory.Create();
// Get a reference to a file and upload it
ShareFileClient file = directory.GetFileClient(fileName);
using (FileStream stream = File.OpenRead(localFilePath))
{
await file.CreateAsync(stream.Length);
var response =await file.UploadRangeAsync(
ShareFileRangeWriteType.Update,
new HttpRange(0, stream.Length),
stream);
Console.WriteLine(response.GetRawResponse().Status);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.