commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wade Chandler <wchand...@redesetgrow.com>
Subject Re: [FileUpload] Testing for existence of file
Date Tue, 21 Dec 2004 15:09:33 GMT
Rhino wrote:
> I'm just polishing my first servlet that uses FileUpload and I'd like to ask
> the experts how they're handling one situation that I encountered in my
> testing.
> 
> While the normal (sensible?) way to do a download is to click the browse
> button, then use the file dialog to find and select the file you want to
> upload to the server, I noticed that it is possible for the user to simply
> type in a file name in the input field. Unfortunately, that means the user
> can type the name of a file that doesn't exist.
> 
> I would like my servlet to handle that situation gracefully: if a user
> enters a file name that doesn't exist, I want to tell the user that this
> happened and let them try again. What is the best way to detect that the
> file name specified in the list of items does not exist on the user's PC?
> 
> I tried using the exists() method in the File class and it worked fine as
> long as I was uploading from my PC to somewhere else on my PC. However, when
> I put the servlet on our server, this logic mistakenly told me that a file
> which certainly DID exist on my PC didn't exist; I assume it was looking on
> the server to see if that file was where I'd specified in the upload.
> 
> How are the experts handling this problem? I don't see anything in the
> FileUpload API that specifically tests for the existence of the file on the
> user's machine so I'm curious what people are doing.
> 
> Rhino
> ---
> rhino1 AT sympatico DOT ca
> "There are two ways of constructing a software design. One way is to make it
> so simple that there are obviously no deficiencies. And the other way is to
> make it so complicated that there are no obvious deficiencies." - C.A.R.
> Hoare
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 
Well, the data will be completely empty once you get to the server side. 
  So now it's up to you whether or not in your context this is an issue 
or not.  You can always explain to the user that you received the file, 
it was empty, and they can make sure this is correct.  It's a limitation 
of html basically.

If you are writing a complicated application to run over the web I 
suggest using web start and java as a front end.  This way you have a 
much richer client yet the application can still be distributed.

If that is over kill for what you need to do, then basically that is the 
only option you have.....either empty files are an error or they are 
not, and if not you should explain to the user what might have happened, 
but not rely on being able to tell exactly what the reason is for the 
file being empty, so you can't force the issue that much except for 
maybe do something like send them back another simple form for 
verification....store off the data on the server for a period of time 
and tell the user how long they have to accept or deny the submit.  If 
that time runs out....delete the info from the server.

You could use a simple thread that sleeps for a special period of time 
for this, or you could have a process that runs watching your files, and 
you can use your db to register things that should be deleted at a 
certain time....how you stop that situation from happening if you need 
to you I'll leave up to you...and there are many other possibilities for 
this as well.

Wade


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message