gpt4 book ai didi

.net - 以编程方式生成 SAS token C#

转载 作者:行者123 更新时间:2023-12-02 05:51:48 25 4
gpt4 key购买 nike

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

我还能够获取复制文件的完整 URL,并且只要容器是公开的,就能够在同一浏览器选项卡中打开它。

现在我正在将我的容器设为私有(private)。我希望有一个简单的 API 可以当场为我提供 SAS URL 和 TOKEN。

有这样的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;

基本上你需要利用BlobSasBuilder类。

关于.net - 以编程方式生成 SAS token C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62604825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com