码迷,mamicode.com
首页 > 其他好文 > 详细

Swagger下载的zip文件无法打开,而且大小比直接下载的要大

时间:2019-12-02 23:50:40      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:dir   script   htm   oct   pre   png   mpeg   rod   rect   

  以前写的一个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‘

  

 

Swagger下载的zip文件无法打开,而且大小比直接下载的要大

标签:dir   script   htm   oct   pre   png   mpeg   rod   rect   

原文地址:https://www.cnblogs.com/lnlvinso/p/11973735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!