在HTTP 307的情况下上传文件

use*_*796 7 java tomcat file-upload

我正在编写一个Spring控制器来处理来自客户端的HTTP PUT请求,并生成S3预先签名的url并发出HTTP 307状态(Temp重定向)代码.所以基本上我正在验证客户端,如果成功,那么我要求他写入s3文件夹.客户端可以写入已签名的URL位置.

现在我担心的是客户端必须上传两次.一旦到我的应用程序服务器再到s3,所以操作将花费两倍的时间.

我的理解是否正确?在这种情况下,客户端实际上是否写了2次?或者客户端是否足够智能,只是首先推送部分有效负载,如果成功,则推送整个负载?

我读到了关于HTTP 100状态代码,但看起来app server/tomcat已经发出它并且不在我的控制之下.

这是我的弹簧控制器

@RequestMapping("/upload")
public ResponseEntity<Void> execute(HttpServletRequest request) throws IOException, ServletException {

  HttpHeaders headers = new HttpHeaders();
  String redirectUrl = getRedirectUrl(requestURI, request.getMethod());
  headers.setLocation(new URI(redirectUrl));

  ResponseEntity<Void> redirectEntity = new ResponseEntity<Void>(null,headers,HttpStatus.TEMPORARY_REDIRECT);
  return redirectEntity;
}
Run Code Online (Sandbox Code Playgroud)

如何防止clint将整个有效负载上传到我的应用服务器?

Mag*_*nus 2

这就是 HTTP 的工作方式,HTTP 除了关闭连接之外没有其他机制来停止文件上传,但如果关闭连接,则无法返回重定向信息。
\n如果您希望客户端直接上传到S3,则需要分两步完成。
\nHave the client request the URL for the file transfer, then have them initiate the transfer with the desired URL.

\n