使用asp.net开发API
能否使用SAS密钥或azure blob SDK将用户重定向到私有Azure Blob存储?
例如,我想做这样的事情:
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;
有没有可能通过在URL中放置密钥来访问私有blob?显然,我不想放置主密钥。
使用asp.net开发API
能否使用SAS密钥或azure blob SDK将用户重定向到私有Azure Blob存储?
例如,我想做这样的事情:
var response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(bloburl);
return response;
有没有可能通过在URL中放置密钥来访问私有blob?显然,我不想放置主密钥。
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;