以编程方式生成SAS令牌C# [英] Generate SAS token c# programmatically

查看:71
本文介绍了以编程方式生成SAS令牌C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将文件1.txt从容器A复制到容器B.

I have copied a file 1.txt from Container A to Container B.

只要容器是公共的,我还可以获得复制文件的完整URL,也可以在同一浏览器选项卡中打开它.

I am also able to get the complete URL of the copied file and also able to open it in the same browser tab as long as container is public.

现在,我将容器设为私有..我希望有一个简单的API可以为我提供SAS URL&当场令牌.

Now I am making my container private .. I was hoping there was a simple API which could give me SAS URL & TOKEN on the spot .

有没有这样的API?

推荐答案

请尝试以下代码:

        Azure.Storage.Sas.BlobSasBuilder blobSasBuilder = new Azure.Storage.Sas.BlobSasBuilder()
        {
            BlobContainerName = "demo-copy",
            BlobName = "test.txt",
            ExpiresOn = DateTime.UtcNow.AddMinutes(5),//Let SAS token expire after 5 minutes.
        };
        blobSasBuilder.SetPermissions(Azure.Storage.Sas.BlobSasPermissions.Read);//User will only be able to read the blob and it's properties
        var sasToken = blobSasBuilder.ToSasQueryParameters(new StorageSharedKeyCredential(accountName, accountKey)).ToString();
        var sasUrl = blobClient.Uri.AbsoluteUri + "?" + sasToken;

基本上,您需要使用

Basically you need to make use of BlobSasBuilder class.

这篇关于以编程方式生成SAS令牌C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆