1

How does file upload/ download works internally, does it require multiple request and response? I am asking this question because I am using spring security for JSON Web Token (JWT) Authentication and if file upload/ download requires multiple request/ response then how am I supposed to send the authentication/ refresh token with the file upload/ download request multiple times.

I am using JWT in Java Swing based desktop application.

Vishrant
  • 10,695
  • 8
  • 48
  • 87
  • The Authentication token is usually sent with every request since these type of webapps are usually stateless, which means that you have no session, so the token is the only thing that authenticates you. – Riiverside May 13 '17 at 18:42
  • @Riiverside that is the only reason I am concerned about the file upload and download as it could be a multiple request. – Vishrant May 13 '17 at 18:43
  • I don't really get what there's to be concerned about. You can simply provide the token with every request as a HTTP header. But you could also upload multiple files in a single multipart request. There's a good example here: https://www.mkyong.com/spring-mvc/spring-mvc-file-upload-example/ – Riiverside May 13 '17 at 18:48
  • @Riiverside thanks for multipart option. I will try that and will get to you. – Vishrant May 13 '17 at 18:57

1 Answers1

0

You can make a single request for the file, providing your token in a bearer header. After authenticating the request (validating the token and checking any claims) the web server should return the file as a stream and specify some response headers to indicate to the client (your Swing desktop application in this case) how to handle the response.

Community
  • 1
  • 1
James Crosswell
  • 514
  • 3
  • 10
  • 1
    what about the file upload, is it possible for REST with JWT? Could you please provide the reference for it? – Vishrant May 13 '17 at 18:43