commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Cooper <mart...@apache.org>
Subject Re: [FileUpload] The getName method yields inconsist value
Date Tue, 06 May 2003 14:54:10 GMT


On Mon, 5 May 2003, Vernon wrote:

> Hi, Martin,
>
> On Mon, 5 May 2003 17:33:04 -0700, Martin Cooper <martinc@apache.org>
> wrote:
>
> > FileUpload is giving you the file name as the browser provided it, so the
> > fact that you are seeing different behaviour across browsers is because
> > the
> > browsers themselves behave differently in this regard. The file upload
> > spec
> > (RFC 1867) is silent on this.
> >
>
> I hope this information will be in the API documentation soon so that
> others will deal with this kind of difference themselve, and won't spend
> hours messed around like I did. I luckly test the code on two browsers in
> the very early stage.

I can add it to the JavaDocs.

>
> > The DiskFileUpload API is the right one to use. It was recently added,
> > but
> > will become part of Beta 2 as soon as I can get that done.
> >
> >>
> >> Also, how to use the new write method with attribute file? I can't see
> >> how
> >> a file instance can be constructed within the content.
> >
> > I'm not sure I understand what you mean. If you had this before:
> >
> > String newFile = "C:\\temp\\upload.dat";
> > item.write(newFile);
> >
> > you would just do this now:
> >
> > File newFile = new File("C:\\temp\\upload.dat");
> > item.write(newFile);
> >
> > Passing a File to write() allows you to do the same as you would have
> > done
> > before, but it also allows you to work with paths and files without
> > having
> > to mess with separators, amongst other things.
> >
>
> So what is the reason(s) the write(String) API is deprecated? It is
> discouraged to use a deprecated method, is it? Also, it is difficult to use
> the write(File) method if the getName() method only return a file name
> only, but not its full path.

Yes, the use of deprecated methods is discouraged, because those methods
will go away in a later release (in this case, RC1). I deprecated the
write(String) method because you can accomplish the same thing - and a lot
more - with write(File).

You absolutely should *not* be using the path provided by getName() to
pass to write(). That path is the one to the original file, on the browser
user's system, ans bears no relationship to the file system the container
is using. Attempting to use this path would be *very* dangerous.

This looks like an excellent reason to remove the write(String) method.
;-)

--
Martin Cooper


>
> Talking about "mess with separators", the lastIndexOfSeparator at (1)
> doesn't return a positive value while a file separator does show up in a
> file name in the following code segment. I have to add the code on (2) to
> get the file name (without path) in a Window OS.
>
> 	// ...
> 	fileName = fi.getName();
> 	int lastIndexOfSeparator = fileName.lastIndexOf(File.separator);		(1)
> 	if(lastIndexOfSeparator == -1)							(2)
> 		lastIndexOfSeparator = fileName.lastIndexOf("\\");
> 	if(lastIndexOfSeparator != -1)
> 		fileName = fileName.substring(lastIndexOfSeparator + 1);
> > --
> > Martin Cooper
> >
> >
>
> Thanks very much for your quick response and helpful information.
>
> Vernon
>
> ---------------------------------------------------------------------
> 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