How do i send a file with jax-rs

前端 未结 1 1198
时光说笑
时光说笑 2020-12-28 19:38

How do send a file for download using jax-rs?

1条回答
  •  囚心锁ツ
    2020-12-28 20:36

    import javax.ws.rs.core.Response;
    import javax.ws.rs.core.Response.ResponseBuilder;
    
    public Response getFile(String contentType) {
    
            File f = new File("/tmp/file.doc");
    
            ResponseBuilder response = Response.ok(f);
            response.type(contentType);
            response.header("Content-Disposition", "attachment; filename=\"file.doc\"");
            return response.build();
        }
    

    0 讨论(0)
提交回复
热议问题