【问题标题】:How do i send a file with jax-rs如何使用 jax-rs 发送文件
【发布时间】:2010-12-07 14:19:16
【问题描述】:

如何使用 jax-rs 发送文件以供下载?

【问题讨论】:

标签: java jakarta-ee download jax-rs


【解决方案1】:
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();
    }

【讨论】:

  • 真的有必要将 f 转换为 Object for Response.ok() 吗?无论如何,文件继承表单对象。
  • @robcast 没必要。我提交了要修复的修改。
猜你喜欢
  • 1970-01-01
  • 2013-07-13
  • 2014-11-06
  • 2011-12-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-11
相关资源
最近更新 更多