saquib-khan
saquib-khan

Reputation: 71

Can we calculate checksum of the file as it is being uploaded by the user in a Spring MVC application?

I have a Spring MVC application that is deployed in Apache Tomcat 9 Webserver. Is it possible to calculate checksum as the file is being uploaded by the user? Where should I even begin looking if I wanted to do this?

To be specific, I understand that I can calculate checksum inside a @Controller class in Spring MVC. However, at this point in time, the file is completely uploaded to the temporary file upload directory. I am, specifically, asking if there is a way to calculate the checksum of the individual parts as a MultipartFile object is being uploaded/created. Do I have to override Apache Tomcat behaviour? Is it possible to do this without modifying Tomcat source code? If not, what is the potential impact of such a modification of Tomcat source code?

I do not understand the intricacies of webservers and would appreciate it if someone could tell me where to start looking.

Upvotes: 2

Views: 929

Answers (1)

Sam YC
Sam YC

Reputation: 11617

Yes, you can't calculate the checksum before you have all the file content. Do you have access to the front end part? If you have, you can calculate the checksum via Javascript and put that information in your request header.

But in this case, you may not be able to use MultipartFile component in Spring, you might need to use apache upload library directly, you have more low level control to allow you to read header before you start to get the file content streaming.

Upvotes: 1

Related Questions