返回文件下载REST(Java)

时间:2015-11-15 22:17:59

标签: java rest

我的REST响应设置如下:

@MethodMapping(value = "/download", httpMethod = HttpMethod.GET)
public Response getLogFile() {
    File log = new File("path");
    if (log.exists())
    {
        return Response.ok(log, MediaType.APPLICATION_OCTET_STREAM)
                .header("Content-Disposition", "attachment; filename=\"" + log.getName() + "\"" ) //optional
                .build();
    }
}

但链接只是给我一个文本响应而不是下载:

{"status":200,"entity":{"path":"path"},"metadata":{"Content-Type":["application/octet-stream"],"Content-Disposition":["attachment; filename\u003d\"proteus.log\""]},"entityClosed":false,"entityBufferred":false}

我使用的两个软件包是javax.ws.rs.core.Response和javax.ws.rs.core.MediaType。

我是否理解错误的功能?谢谢!

0 个答案:

没有答案