Swagger下载的zip文件无法打开,而且大小比直接下载的要大
以前写的一个rest提供的是浏览器下载zip包的功能,前端界面调用rest可以正常地下载。
今天使用Swagger来调试下载功能时,发现下载的zip包打不开,而且大小也比直接在浏览器中输入rest地址下载的zip包要大。
浏览器中输入rest地址下载的zip包是好的,大小也是对的。
rest的@ApiOperation注解的produces属性需要配置为"application/octet-stream"
@ApiOperation(value = "下载zip", produces = "application/octet-stream")
response设置如下:
response.setContentType("application/zip"); response.setHeader("Content-Disposition", "attachment;filename=test.zip");
Content-Disposition参数:attachment --- 作为附件下载 inline --- 在线打开
application/octet-stream是MIME类型。 不清楚具体的类型时,可以指定为二进制类型
‘doc‘ => ‘application/msword‘, ‘bin‘ => ‘application/octet-stream‘, ‘exe‘ => ‘application/octet-stream‘, ‘so‘ => ‘application/octet-stream‘, ‘dll‘ => ‘application/octet-stream‘, ‘pdf‘ => ‘application/pdf‘, ‘ai‘ => ‘application/postscript‘, ‘xls‘ => ‘application/vnd.ms-excel‘, ‘ppt‘ => ‘application/vnd.ms-powerpoint‘, ‘dir‘ => ‘application/x-director‘, ‘js‘ => ‘application/x-javascript‘, ‘swf‘ => ‘application/x-shockwave-flash‘, ‘xhtml‘ => ‘application/xhtml+xml‘, ‘xht‘ => ‘application/xhtml+xml‘, ‘zip‘ => ‘application/zip‘, ‘mid‘ => ‘audio/midi‘, ‘midi‘ => ‘audio/midi‘, ‘mp3‘ => ‘audio/mpeg‘, ‘rm‘ => ‘audio/x-pn-realaudio‘, ‘rpm‘ => ‘audio/x-pn-realaudio-plugin‘, ‘wav‘ => ‘audio/x-wav‘, ‘bmp‘ => ‘image/bmp‘, ‘gif‘ => ‘image/gif‘, ‘jpeg‘ => ‘image/jpeg‘, ‘jpg‘ => ‘image/jpeg‘, ‘png‘ => ‘image/png‘, ‘css‘ => ‘text/css‘, ‘html‘ => ‘text/html‘, ‘htm‘ => ‘text/html‘, ‘txt‘ => ‘text/plain‘, ‘xsl‘ => ‘text/xml‘, ‘xml‘ => ‘text/xml‘, ‘mpeg‘ => ‘video/mpeg‘, ‘mpg‘ => ‘video/mpeg‘, ‘avi‘ => ‘video/x-msvideo‘, ‘movie‘ => ‘video/x-sgi-movie‘
相关推荐
SAMXIE 2020-11-04
XuDanT 2020-09-16
permanent00 2020-09-15
哈嘿Blog 2020-09-08
Qizonghui 2020-08-02
莫问前程 2020-08-02
SAMXIE 2020-07-26
XuDanT 2020-07-24
莫问前程 2020-07-18
Qizonghui 2020-07-18
coolhty 2020-07-05
Qizonghui 2020-06-28
Qizonghui 2020-06-25
莫问前程 2020-06-22
SAMXIE 2020-06-14
莫问前程 2020-06-14
XuDanT 2020-06-07
qingjiuquan 2020-06-07
TimeMagician 2020-06-03