commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mfncoo...@gmail.com>
Subject Re: fileupload issue
Date Mon, 08 Nov 2004 17:43:45 GMT
On Mon, 8 Nov 2004 15:37:57 -0000, Pawson, David
<david.pawson@rnib.org.uk> wrote:
> 
> I'm running tomcat 5.0.27, with fileupload.
> 
> Currently testing on windows 2000, with a production target of Linux.
> 
> Given a windows file, with a name containing spaces
> 'my documents/file.ext' I'm presuming Linux may well cough
> at creating such a file.
> 
> Is there a way of uploading the file (with spaces)
> and then writing the file with, say, spaces replaced
> with underscore?
> 
> I'm currently using
> 
>        String fileName = fn;
>        if (fileName.indexOf(" ") != -1)
>            fileName ="'"+fileName+"'"; // quote if holds spaces
> 
>        File uploadedFile = new File(AreaDir +sd.pathsep +fn);
> 
>        if ((uploadedFile.exists() && sd.overwrite) ||
>            (!uploadedFile.exists()))
>        {
>            if ((uploadedFile.exists() && sd.overwrite)){
>                logger.info(userName + "file overwrite on " + fn);
>                //Send email too. FIXME
>            }
> 
>            try {
>                item.write(uploadedFile);
>            } catch (java.lang.Exception err) {
>                retval= sd.fileWriteError;//failed upload
>                logger.error(userName+
>                             "Error on writing file to the archive. " + err);
>            }//end catch
>        }
>        else {
>            retval = sd.fileExistsError; //file exists
>            }
>        return retval;
> 
> I can't see how I can intercept the filename
> to make the changes needed?

I guess I'm not understanding what you mean by "intercept the
filename". You have *complete* control over the file name if you're
writing the file to disk. You can name the file whatever you want and
put it wherever you want. In the code above, there is only one line
(item.write()) that has anything to do with FileUpload - the rest is
your file name manipulation code. Isn't that where you'd "intercept"
it and change the name to whatever you want? I'm not getting it,
sorry...

--
Martin Cooper


> Regards DaveP.
> 
> **** snip here *****
> 
> --
> DISCLAIMER:
> 
> NOTICE: The information contained in this email and any attachments is
> confidential and may be privileged.  If you are not the intended
> recipient you should not use, disclose, distribute or copy any of the
> content of it or of any attachment; you are requested to notify the
> sender immediately of your receipt of the email and then to delete it
> and any attachments from your system.
> 
> RNIB endeavours to ensure that emails and any attachments generated by
> its staff are free from viruses or other contaminants.  However, it
> cannot accept any responsibility for any  such which are transmitted.
> We therefore recommend you scan all attachments.
> 
> Please note that the statements and views expressed in this email and
> any attachments are those of the author and do not necessarily represent
> those of RNIB.
> 
> RNIB Registered Charity Number: 226227
> 
> Website: http://www.rnib.org.uk
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
>

---------------------------------------------------------------------
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