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

Posted lnlvinso

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘

  

 

以上是关于Swagger下载的zip文件无法打开,而且大小比直接下载的要大的主要内容,如果未能解决你的问题,请参考以下文章

Spring REST / Swagger / Postman - 正在下载损坏/空白文件

unix 命令 'zip' 或 'compress' - 文件大小比以前大

ipad下下来是压缩文件,网上说是把zip.改成ipa,在哪改,怎么改?

压缩文件zip与rar有啥区别?

ZipArchive php 获取损坏或空的 zip

如何在 Swagger-UI 中打开本地文件