Content-disposition中Attachment和inline的区别
来源:互联网 发布:网络攻防大赛 形式 编辑:程序博客网 时间:2024/05/29 15:49
java web中下载文件时,我们一般设置 Content-Disposition告诉浏览器下载文件的名称,是否在浏览器中内嵌显示.
Content-disposition: inline; filename=foobar.pdf
表示浏览器内嵌显示一个文件
Content-disposition: attachment; filename=foobar.pdf
表示会下载文件,如火狐浏览器中
spring mvc中
@ResponseBody@RequestMapping(value = "/download",produces="application/octet-stream")public byte[] downloadFile(HttpServletRequest request, HttpServletResponse response,String contentType2)throws IOException {byte[]bytes=FileUtils.getBytes4File("D:\\Temp\\cc.jpg");response.addHeader("Content-Disposition", "inline;filename=\"a.jpg\"");return bytes;}
如上代码中是内嵌显示图片呢?还是会弹框下载呢?
答案是:弹框下载
为什么呢?设置为inline应该是内嵌显示啊!
因为response content type设置成了"application/octet-stream"
注意:我们说是内嵌显示还是下载,那 一定是针对可内嵌显示的类型,例如"image/jpeg","image/png"等.
看下面的例子:设置response content type为" image/jpeg"
@ResponseBody@RequestMapping(value = "/download",produces="image/jpeg")public byte[] downloadFile(HttpServletRequest request, HttpServletResponse response,String contentType2,String downloadType)throws IOException {byte[]bytes=FileUtils.getBytes4File("D:\\Temp\\cc.jpg");response.addHeader("Content-Disposition", downloadType+";filename=\"a.jpg\"");return bytes;}
在浏览器中访问:http://localhost:8080/tv_mobile/video/download?downloadType=inline 时就内嵌显示:
当在浏览器中访问:http://localhost:8080/tv_mobile/video/download?downloadType=attachment 时就弹框下载.
转载自:http://itindex.net/detail/52857-content-disposition-attachment?utm_source=tuicool&utm_medium=referral
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别、ContentType设置
- Content-disposition中Attachment和inline的区别
- Content-disposition中Attachment和inline的区别
- 文件上传Content-disposition中Attachment和inline的区别
- Java在上传或下载时header中Content-Disposition的作用以及Content-disposition中Attachment和inline的区别
- attachment和inline的区别
- attachment和inline的区别 下载文件
- Content-disposition","attachment; filename=中文名 乱码
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- header中Content-Disposition的作用
- android studio 版本控制 .gitignore 文件配置 &&移除已上传到git的不需版本控制的文件
- Leetcode Combinations
- 欢迎使用CSDN-markdown编辑器
- ubuntu12.04 +kinect1 骨骼追踪
- 系统测试——测试用例设计
- Content-disposition中Attachment和inline的区别
- Android butterknife OnClick 没反应
- 利用python对多个txt文件中的数据进行筛选
- SVN merge详细说明
- js放大镜效果
- php 根据url自动生成缩略图,并处理高并发问题
- 禅道环境搭建
- 转:Unity延时功能的几种实现
- 博客-重新出发