HttpResponseMessage重定向到私有Azure Blob存储 [英] HttpResponseMessage Redirect to Private Azure Blob Storage

查看:151
本文介绍了HttpResponseMessage重定向到私有Azure Blob存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用asp.net开发API

Developing an API using asp.net

是否可以将用户重定向到私有天蓝色blob存储?我可以使用SAS密钥还是azure blob SDK来做到这一点吗?

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?

例如,我想做这样的事情:

For example I want to do something like this:

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

是否可以通过在URL中放置密钥来访问私有Blob?显然我不想放主密钥.

Is it possible to access a private blob by putting a key in the URL? Obviously i dont want to put the master key though.

推荐答案

是否可以将用户重定向到私有的天蓝色blob存储?能 我是使用SAS密钥还是azure blob SDK来做到这一点的?

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.

Yes, it is entirely possible to redirect a user to a private blob. You would need to create a Shared Access Signature (SAS) with at least Read permission and append that SAS token to your blob URL and do a redirect to that 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;

这篇关于HttpResponseMessage重定向到私有Azure Blob存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆