2

I have web application where I am uploading the large file more than 1 GB from browser to the server. Depending on network speed some time it will take more than 1 hour.

Server endpoint is secured with OAuth. When upload request is sent from browser it has valid token with 1 hour expiry.

In case of large file upload, it gives Unauthorised error because of token expiry after 1 hour.

How can I solve this problem where token should validate only in the beginning of the request not after complete file upload?

Technology used

  1. AngularJs - UI
  2. SpringBoot version 2 - Backend
  3. POST request Content-Type: Multipart/form-data

I dont have option to increase the token expiry beyond 1 hour.

1 Answers1

0

The reason is that the tomcat will receive the file firstly, then dispatch the servlet request to your controller. When the upload takes too long time and the token has already expired, the security check will return 401, and your request will never enter the controller (the security check is before your controller).

You can put a breakpoint in your controller with the MultiPartFile parameter, then try to upload a huge size file to verify what I said.

One possible solution is you resolve the servlet yourself, maybe something like:

uploadFile(HttpServletRequest rawRequest)

Then when a token already expired, you can refresh it rather than return 401 then discard the already uploaded file.

Hope this may help you, and if you have a better idea, please let us know. Thank you!

useful link: https://docs.spring.io/spring-framework/docs/5.3.x/reference/html/web.html#mvc-multipart

Lang
  • 943
  • 13
  • 33