This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to check the integrity of uploaded file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Servlets
Bookmark "How to check the integrity of uploaded file" Watch "How to check the integrity of uploaded file" New topic

How to check the integrity of uploaded file

Yongping Wang
Ranch Hand

Joined: May 15, 2001
Posts: 40
A servlet functions to upload a file from local machine to server host. But sometimes, user would close web browser or hit back button during the process of uploading a file and only part of the file was uploaded to server side. I need to remove any incomlete files but how can I check the integrity of a file. Thanks in advance. Have a nice weekend.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

If you are using something like com.oreilly.servlet, you should find that it will throw an Exception you can catch (most likely unexpected end of part)?

It's fairly difficult to separate out (especially with more than one file, or multiple form elements) exactly how much of the POST data is 'the file'.. but what you Might attempt is to retrieve that HTTP header that tells you the size of the POST, and if your file is signifigantly smaller than this, you know it got chopped off.

But there's got to be a better way, right? Hmm...
I agree. Here's the link:
subject: How to check the integrity of uploaded file
It's not a secret anymore!