简体   繁体   English

共享访问从 windowsazure.storage 移动到 Azure.Storage.Files

[英]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关于如何创建,请参考以下代码

  1. Install package安装包
dotnet add package Azure.Storage.Files.Shares
  1. Code代码
# 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);
}

在此处输入图片说明 在此处输入图片说明

For more details, please refer to the sample .更多详细信息,请参阅示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 WindowsAzure.Storage 迁移到 Azure.Storage 包时从 CloudStorageAccount 引用服务 - Referencing services from CloudStorageAccount when migrating from WindowsAzure.Storage to Azure.Storage packages 从“WindowsAzure.Storage”迁移时,我应该为 Azure 表使用什么 package - What package should I use for Azure Tables when migrating away from "WindowsAzure.Storage" WindowsAzure.Storage没有使用.Net Core 1.0 - WindowsAzure.Storage on not working on .Net Core 1.0 WindowsAzure.Storage使用C#mono - WindowsAzure.Storage using C# mono ExecuteQuery WindowsAzure.Storage 5.0.3没有扩展方法 - ExecuteQuery WindowsAzure.Storage 5.0.3 no extension method 在 C# .NET Core 中使用 Azure TableStorage - Nuget Package WindowsAzure.Storage Alternative - Using Azure TableStorage in C# .NET Core - Nuget Package WindowsAzure.Storage Alternative WindowsAzure.Storage,版本= 9.3.0.0-异常无法加载文件或程序集 - WindowsAzure.Storage, Version=9.3.0.0 - exception could not load file or assembly 如何在Visual Studio 2013中安装WindowsAzure.Storage? - How do I install WindowsAzure.Storage in Visual Studio 2013? 将WindowsAzure.Storage安装到针对Xamarin平台的PCL - Install WindowsAzure.Storage to PCL targeting Xamarin platforms 我应该使用哪个版本的WindowsAzure.Storage? - Which version of WindowsAzure.Storage should I use?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM