如何在不立即保存的情况下将文件发送给客户端

How to send file to client without saving it immadiately

我需要使用 rest api 从我的后端应用程序向客户端发送文件。现在这段代码工作得很好

@GET
@Produces("application/vnd.ms-excel")
public Response getFile(){
 StreamingOutput fileStream = service.doSomeLogic();

 return Response.ok(fileStream, "application/vnd.ms-excel").header("Content-Disposition", "attachment; filename=someFile.xls").build();
}

我的问题是,当我输入给定的端点时,文件会立即下载,没有 'menu' 选择保存位置或如何命名文件。在我使用 Spring 并返回 Response byte[] 或类似的东西之前,它按我现在的需要工作 - 没有立即保存。

我试过发回byte[],但效果是一样的。

设置->高级
这是 Chrome 中的设置示例,如果您禁用它,它将询问位置,否则将直接下载到默认位置。


下面是 Mozilla

的示例