http://www.concretepage.com/webservices/download-file-using-restful-web-services-jax-rs,下面是从jax-rs rest服务下载文件的代码
@Path("/restwb")
public class FileResource {
@GET
@Path("/download/{fname}/{ext}")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response downloadFile(@PathParam("fname") String fileName,@PathParam("ext") String fileExt){
File file = new File("C:/temp/"+fileName+"."+fileExt);
ResponseBuilder rb = Response.ok(file);
rb.header("Content-Disposition", "attachment; filename=" + file.getName());
Response response = rb.build();
return response;
}
} 我现在的问题是,为了下载文件对象的list (ArrayList),响应应该是什么样子的?
我们能不能写:
List<File> lFiles = new ArrayList<File>();
...
ResponseBuilder rb = Response.ok(lFiles);发布于 2016-11-17 21:05:01
无法在同一请求中下载多个文件。如果您需要下载多个文件,您必须创建一个归档文件,然后下载存档文件。
这是因为文件的原始字节是在HTTP响应中发送的,HTTP头用于如何翻译内容,您只能设置一组报头HTTP响应。
https://stackoverflow.com/questions/40664639
复制相似问题