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

标签 wcf rest azure blob azure-storage

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

    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;

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

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

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

最佳答案

可能与 this question 重复.

由于 Stive Marx 表示无法控制 Azure Lbob 的“内容处置” header ,因此无法强制浏览器 (IE) 下载该文件。将内容类型设置为“application/octet-stream”可能会强制某些浏览器下载文件,而不是打开它,但显然它不适用于 IE。

关于wcf - 使用 Azure Blob 存储从 WCF REST 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8764400/

相关文章:

java - 分离 Spring Rest 处理

azure - 在 Azure 中,如何在不使用 git 的情况下部署 functionapp 代码?

c# - C#中的线程问题

c# - 所有实体上的 QueryInterceptor

jquery - 无法将 json 对象传递给 python 服务器程序

mobile - 从命令行使用 Azure 移动服务进行测试

sql-server - Azure 网站连接到不同区域的 Azure SQL 数据库的性能问题

c# - 通过 JQuery 使用 WCF POST 的 400 错误请求 HTTP 响应

c# - 获取 wcf 服务的已连接客户端列表

json - 使用JSON文件的JAX-RS生成错误415