繁体   English   中英

使用Azure Blob存储从WCF REST下载文件

[英]Downloading file from WCF REST with Azure Blob Storage

我有一个带有Azure Blob存储的WCF REST服务。 我不想将我的服务用作流的代理,所以我想将客户端的请求重定向到绝对blob URL,但它将重定向到文件并尝试直接打开它。 当服务器将请求重定向到绝对Blob网址时,我只想开始下载过程。 我尝试过的代码如下:

    var sas = blob.GetSharedAccessSignature(new SharedAccessPolicy
    {
        Permissions = SharedAccessPermissions.Read,
        SharedAccessStartTime = DateTime.UtcNow,
        SharedAccessExpiryTime = DateTime.UtcNow + TimeSpan.FromMinutes(1)
    });
    WebOperationContext.Current.OutgoingResponse.ContentType = blob.Properties.ContentType;
    WebOperationContext.Current.OutgoingResponse.ContentLength = blob.Properties.Length;
    WebOperationContext.Current.OutgoingResponse.Location = blob.Uri.AbsoluteUri+sas;
    WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;

PS我试图将状态代码更改为“重定向”,“已移动..等”,但没有任何变化。

更新如果我将ContentType更改为application / octet-stream,则在IE中将得到如下结果:

<base64Binary xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
...
</base64Binary>

此问题可能重复。

由于Stive Marx表示无法控制Azure Lbob的“内容配置”标头,因此无法强制浏览器(IE)下载文件。 将内容类型设置为“应用程序/八位字节流”可能会迫使某些浏览器删除文件,而不是打开文件,但显然不适用于IE。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM