How do i send a file with jax-rs

2020-02-22 07:26发布

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

1条回答
Viruses.
2楼-- · 2020-02-22 08:08
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();
    }
查看更多
登录 后发表回答