我是否需要内容类型:应用程序/八位字节流的文件下载? [英] Do I need Content-Type: application/octet-stream for file download?

查看:137
本文介绍了我是否需要内容类型:应用程序/八位字节流的文件下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

借助 HTTP标准说:

如果这个头[内容处置:附件]在响应用于
  与应用程序/八位字节流内容类型,隐含
  的建议是,用户代理不应该显示的响应,但
  直接输入`保存响应,...对话框。

If this header [Content-Disposition: attachment] is used in a response with the application/octet-stream content-type, the implied suggestion is that the user agent should not display the response, but directly enter a `save response as...' dialog.

我读到为

Content-Type: application/octet-stream
Content-Disposition: attachment

不过,我本来以为内容类型应用程序/ PDF 图像/ PNG

我应该有内容类型:应用程序/八位字节流如果我想浏览器下载文件

Should I have Content-Type: application/octet-stream if I want browsers to download the file?

推荐答案

没有。

内容类型应该是不管它是已知的,如果你知道它。 应用程序/八位字节流在RFC 2046定义为任意的二进制数据,这里有它是适合其唯一的预期目的实体的明确重叠保存到磁盘,并从是什么,威比外面这一点。还是要看它从另一个方向;人们可以放心地使用应用程序/八位字节流唯一要做的就是将它保存到文件,并希望其他人知道它是。

The content-type should be whatever it is known to be, if you know it. application/octet-stream is defined as "arbitrary binary data" in RFC 2046, and there's a definite overlap here of it being appropriate for entities whose sole intended purpose is to be saved to disk, and from that point on be outside of anything "webby". Or to look at it from another direction; the only thing one can safely do with application/octet-stream is to save it to file and hope someone else knows what it's for.

您可以结合使用内容处置的与其他内容类型,如图像/ PNG 或甚至的text / html 来表示你想要保存,而不是显示。它曾经是,一些浏览器会忽略它在的text / html 的情况如此,但我认为这是一些很久以前在这一点(我要去睡觉很快,所以我不打算马上开始测试一大堆的浏览器;也许以后)

You can combine the use of Content-Disposition with other content-types, such as image/png or even text/html to indicate you want saving rather than display. It used to be the case that some browsers would ignore it in the case of text/html but I think this was some long time ago at this point (and I'm going to bed soon so I'm not going to start testing a whole bunch of browsers right now; maybe later).

2616也提到扩展标记的可能性,这几天大多数浏览器识别在线来的意思是你想要的实体显示如果可能的话(也就是说,如果它是一个键入浏览器知道如何显示的,否则它有在这个问题上没有选择)。当然,这是默认的行为,无论如何,但它意味着你可以包括文件名头,它的浏览器将使用(也许还包括一些调整一部分,这样的文件扩展名匹配本地系统规范的内容类型的问题,也许不是)作为建议,如果用户试图保存。

RFC 2616 also mentions the possibility of extension tokens, and these days most browsers recognise inline to mean you do want the entity displayed if possible (that is, if it's a type the browser knows how to display, otherwise it's got no choice in the matter). This is of course the default behaviour anyway, but it means that you can include the filename part of the header, which browsers will use (perhaps with some adjustment so file-extensions match local system norms for the content-type in question, perhaps not) as the suggestion if the user tries to save.

因此​​:

Content-Type: application/octet-stream
Content-Disposition: attachment; filename="picture.png"

意思是我不知道什么是地狱,这是请保存为一个文件,preferably命名picture.png。

Means "I don't know what the hell this is. Please save it as a file, preferably named picture.png".

Content-Type: image/png
Content-Disposition: attachment; filename="picture.png"

表示这是一个PNG图像,请保存为一个文件,preferably命名picture.png。

Means "This is a PNG image. Please save it as a file, preferably named picture.png".

Content-Type: image/png
Content-Disposition: inline; filename="picture.png"

表示这是一个PNG图像,请显示它,除非你不知道如何显示PNG图像。否则,如果用户选择保存,我们建议的名称picture.png为你保存文件作为

Means "This is a PNG image. Please display it unless you don't know how to display PNG images. Otherwise, or if the user chooses to save it, we recommend the name picture.png for the file you save it as".

那些承认在线有些人会永远使用它,而如果用户已经选择链接另存为,而不是他们是否会选择其他人会用它浏览器拯救,而观看(或至少IE曾经是这样的,它可能已经在几年前更改)。

Of those browsers that recognise inline some would always use it, while others would use it if the user had selected "save link as" but not if they'd selected "save" while viewing (or at least IE used to be like that, it may have changed some years ago).

这篇关于我是否需要内容类型:应用程序/八位字节流的文件下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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