gpt4 book ai didi

c# - HttpResponseMessage 重定向到私有(private) Azure Blob 存储

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:35 24 4
gpt4 key购买 nike

使用 asp.net 开发 API

是否可以将用户重定向到私有(private) Azure Blob 存储?我可以使用 SAS key 或 azure blob SDK 执行此操作吗?

例如我想做这样的事情:

var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;

是否可以通过将 key 放入 URL 来访问私有(private) blob?显然我不想把主 key 放在一起。

最佳答案

Is it possible to redirect a user to a private azure blob storage? Can i do this using SAS keys or the azure blob SDK?

是的,完全有可能将用户重定向到私有(private) blob。您需要创建一个 Shared Access Signature (SAS)至少 Read权限并将该 SAS token 附加到您的 blob URL 并重定向到该 URL。

你的代码看起来像这样:

        var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("container-name");
var blob = container.GetBlockBlobReference("blob-name");
var sasToken = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
{
Permissions = SharedAccessBlobPermissions.Read,
SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1)//Assuming you want the link to expire after 1 hour
});
var blobUrl = string.Format("{0}{1}", blob.Uri.AbsoluteUri, sasToken);
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;

关于c# - HttpResponseMessage 重定向到私有(private) Azure Blob 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42162759/

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