HttpResponseMessage 重定向到私有 Azure Blob 存储
HttpResponseMessage Redirect to Private Azure Blob Storage
使用 asp.net
开发 API
是否可以将用户重定向到私有 Azure Blob 存储?我可以使用 SAS 密钥或 azure blob SDK 执行此操作吗?
例如我想做这样的事情:
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;
是否可以通过将密钥放入 URL 来访问私有 blob?显然我不想放主密钥。
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?
是的,完全可以将用户重定向到私有 blob。您需要创建一个至少具有 Read
权限的 Shared Access Signature (SAS)
并将该 SAS 令牌附加到您的 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;
使用 asp.net
开发 API是否可以将用户重定向到私有 Azure Blob 存储?我可以使用 SAS 密钥或 azure blob SDK 执行此操作吗?
例如我想做这样的事情:
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;
是否可以通过将密钥放入 URL 来访问私有 blob?显然我不想放主密钥。
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?
是的,完全可以将用户重定向到私有 blob。您需要创建一个至少具有 Read
权限的 Shared Access Signature (SAS)
并将该 SAS 令牌附加到您的 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;