Java 为什么找不到MIME媒体类型应用程序/zip?
我需要在RESTAPI中返回zip文件,但我收到的MIME媒体类型应用程序/zip未找到Java 为什么找不到MIME媒体类型应用程序/zip?,java,web-services,rest,media-type,Java,Web Services,Rest,Media Type,我需要在RESTAPI中返回zip文件,但我收到的MIME媒体类型应用程序/zip未找到 @Produces({ "application/zip" }) public Response convertFile(){ . . . return Response.ok(result, "application/zip").build(); } 试试这个: @Produces("application/zip") return Response
@Produces({ "application/zip" })
public Response convertFile(){
.
.
.
return Response.ok(result, "application/zip").build();
}
试试这个:
@Produces("application/zip")
return Response
.ok(FileUtils.readFileToByteArray(resultFile))
.type("application/zip")
.header("Content-Disposition", "attachment; filename=\"yourfile.zip\"")
.build();
使用MediaType#多部分表单(数据)类型
阅读:你也可以这么做
@Produces("application/zip")
public File getAZipFile(){
//your controller code which returns a file
return file;
}
注意:Accept头必须是application/zip您需要为application/zip
和Java类型创建自己的头,或者只使用application/octect-stream