commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vernon <vern...@gatewaytech.com>
Subject Re: [FileUpload] The getName method yields inconsist value
Date Tue, 06 May 2003 03:55:10 GMT
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.

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

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

Mime
View raw message