我已将文件 1.txt 从容器 A 复制到容器 B。
我还可以获取复制文件的完整 URL,并且只要容器是公共的,就可以在同一个浏览器选项卡中打开它。
现在我将我的容器设为私有。我希望有一个简单的 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;
Run Code Online (Sandbox Code Playgroud)
基本上你需要利用BlobSasBuilder类。
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |