是否有强制的Azure CDN文件下载作为浏览器附件的方法呢? [英] Is there an approach to force a Azure CDN file to download as a browser attachment?

查看:116
本文介绍了是否有强制的Azure CDN文件下载作为浏览器附件的方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建一个ASP.NET Web应用程序,其与DAM(数字资产管理)系统的集成。大坝专卖店文件的Azure Blob存储,使他们公开使用的Azure CDN。

We're building an ASP.NET web application which integrates with a DAM (digital asset management) system. The DAM stores files in Azure blob storage and makes them available publicly using Azure CDN.

我们将作出这些文件(大部分都是PDF格式),可从我们的Web应用程序下载。当用户请求这些文件中的一个,我们将提供这将返回相关的文件下载之前在服务器上运行约code(日志下载等),自定义URL。

We will be making these files (most are PDFs) available to download from our web app. When a user requests one of these files we will provide a custom URL which will run some code on the server (logging the download etc) before returning the relevant file for download.

客户要求的文件始终返回浏览器附件(即内容处置附件标头)。我很好奇,我这里的选项。

The client requires that the file is always returned as a browser attachment (i.e. content disposition attachment header). I am curious about what options I have here.

我的理想是,该CDN URL是抽象的和我的自定义URL是该文件的公开网址。这将让我来设置相关的响应头等等。但是,我认为唯一的解决办法这里将是从CDN下载的文件,并将它缓存这将混淆CDN的目的,我的Web服务器上。所以presumably我必须将客户端重定向到CDN公共网址,一旦我做我的服务器处理。但后来有没有办法,我可以保证文件由天青返回了正确的响应头,以确保浏览器的默认下载行为被委派?

My ideal would be that the CDN URL is abstracted and my custom URL is the public URL for the file. That would allow me to set relevant response headers etc. However, I assume the only solution here would be to download the file from CDN and cache it on my web server which would obfuscate the CDN's purpose. So presumably I have to redirect the client to the CDN public URL once I've done my server processing. But then is there a way I can ensure the file is returned by Azure with the correct response headers to ensure the browser's default download behaviour is delegated?

*更新*

在看到这个问题的答案我意识到我也许问错了问题。谢谢你们谁在这里得到解答。 <一href=\"http://stackoverflow.com/questions/35752650/what-are-the-implications-of-serving-different-file-types-all-as-application-oct\">Follow-up问题是这里。

In seeing the answers to this question I realised I was perhaps asking the wrong question. Thank you to those of you who answered here. Follow-up question is here.

推荐答案

您需要,以便配置上Blob存储默认版本为它显示所需的头未验证客户端。在提问<一href=\"http://stackoverflow.com/questions/25472152/keep-getting-old-version-even-after-changing-the-default-service-version-on-azu\">this问题有code,使其工作。

TL;DR

You need to configure the default version on the blob storage in order for it to show the required header to non-authenticated clients. the question in this question has the code to make it work.

一旦设置,并为匿名客户端的CDN将复制整个头,并预期它应该工作的工作。

Once this is set, and working for anonymous clients the CDN will copy all of the headers across and it should work as expected.

的功能是present,您可以在设置ContentDisposition斑点属性然而,虽然这将设置在斑点的属性,它不穿过到头部。

The functionality is present, you can set ContentDisposition on a blob property However, while this will set the property on the blob, it does not pass through to the header.

我用下面这个测试使用PowerShell(只是因为它比C#快)

I tested this with Powershell using the following (just because its quicker than c#)

$context = New-AzureStorageContext -StorageAccountName $StorageAccountName -StorageAccountKey $StorageAccountKey 

$container = Get-AzureStorageContainer -Name $ContainerName -Context $context 

$blobref = ($script:container.CloudBlobContainer.GetBlobReferenceFromServer("images/pier.jpg"))
$blobref.Properties
$blobref.Properties.ContentDisposition = 'attachment; filename="fname.ext"'  
$blobref.SetProperties()  

$blobref = ($script:container.CloudBlobContainer.GetBlobReferenceFromServer("images/pier.jpg"))
$blobref.Properties

将会产生(其中包括)

Which produces (amongst others)

ContentDisposition:附件;文件名=fname.ext

ContentDisposition : attachment; filename="fname.ext"

不过未设置任何

([system.Net.HttpWebRequest]::Create($blobref.Uri.AbsoluteUri)).getresponse() 

(回答评论,.这些返回的头 - 实验的同时我也尝试过使用和不使用的contentType - 因此,它在这里空白)

(to answer comment,. these are the headers returned - while experimenting I also tried with and without a contenttype - hence it being blank here)

IsMutuallyAuthenticated : False
Cookies                 : {}
Headers                 : {x-ms-request-id, x-ms-version, x-ms-lease-status, x-ms-blob-type...}
SupportsHeaders         : True
ContentLength           : 142224
ContentEncoding         : 
ContentType             : 
CharacterSet            : 
Server                  : Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
LastModified            : 01/03/2016 11:29:04
StatusCode              : OK
StatusDescription       : OK
ProtocolVersion         : 1.1
ResponseUri             : https://xxxx.blob.core.windows.net/cdn/images/pier.jpg
Method                  : GET
IsFromCache             : False

和自CDN将从HTTP头本身只复制信息,这个数据不使其成的CDN。

And since CDN will only copy the information from the HTTP headers themselves, this data isn't making it into CDN.

有关最著名本身PowerShell的不发送X-MS-版本的原因,所以我回落到远程登录这确实产生了头 -

For reasons best known to itself Powershell wasn't sending the x-ms-version, so I fell back to telnet which did indeed produce the header -

HEAD  /cdn/images/pier.jpg HTTP/1.1
HOST: xxxx.blob.core.windows.net
x-ms-version: 2015-04-05

HTTP/1.1 200 OK
Content-Length: 142224
Last-Modified: Tue, 01 Mar 2016 11:29:04 GMT
Accept-Ranges: bytes
ETag: "0x8D341C4B1C4F34F"
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: b4f41b01-0001-00d7-7cc9-7384c9000000
x-ms-version: 2015-04-05
x-ms-lease-status: unlocked
x-ms-lease-state: available
x-ms-blob-type: BlockBlob
Content-Disposition: attachment; filename="fname.ext"
Date: Tue, 01 Mar 2016 14:49:17 GMT

这篇关于是否有强制的Azure CDN文件下载作为浏览器附件的方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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