dropwizard下载功能

    xiaoxiao2021-03-30  30

    这两天在使用dropwizard框架进行开发,在前任大牛的框架上开发的,刚好使用到下载功能,大家都知道http://www.baidu.com/test.rar,只要在web应用下面有这个test.rar,而且路径正确就能进行下载,只要在浏览器地址中输入http://www.baidu.com/test.rar,这个就能下载了,可偏偏到了dropwizard就不行了,我查看了dropwizard的帮助文档,也没有找到原因和解决办法,我估计是dropwizrd加载的时候把所有的resource中的get post delete等注解的方法加载成提供的接口,但是我们使用的下载http://www.baidu.com/test.rar,是不可能做成resource的,因此就会包http://www.baidu.com/test.rar路径找不到404问题,那如何解决呢?就是使用Response.ok().header().build();

    return Response.ok(new File(filePath)).header("Content-Disposition", "attachment; filename="+wzFileGain.getFileName()) .build();

    final byte[] bytes = IOUtils.toByteArray(new FileInputStream(this.dest));                  return Response.ok().entity(new StreamingOutput() {             @Override             public void write(OutputStream out) throws IOException, WebApplicationException {                 out.write(bytes);             }         }).type("application/ms-excel").header("Set-Cookie", "fileDownload=true; path=/")                         .header("Content-Disposition", "attachment; filename=" + name).build();

    现在一直不知道Response.ok(obj,MediaTeype) 这个MediaType有哪些东西  ,还要就是header("")这里面与什么,如果有人知道请告诉我

    转载请注明原文地址: https://ju.6miu.com/read-665137.html

    最新回复(0)