Re: [FileUpload] Getting wrong filename from FileItem

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Knezevic, Mihael
thanks to all the responses for my question.

actually i didn't know that it was a browser "thing". i thought it was an
operating system thing. thanks for clearing this up. and as this is a browser
specific thing IMHO there should be just a change in the docu where you
should add the fact that the IE is not behaving like any other browser with
the method getName. that would be of much help.

and this is the kind of "feature" i don't like of MS software.

Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:

> I know, I've run into this myself... But, it should be a fairly trivial
> exercise to write code to extract just the filename (as I believe you've
> done).  This makes sense to me as an additional method.  That way no
> existing code gets broken, but newer code can use the new method, which
> works as getName() probably should have been working all along anyway
> (IMHO).
>
> Frank
>
> Dakota Jack wrote:
> > The data difference is not in the code but in the request data from
> > the browser.  IE puts in the full name and other browsers put in just
> > the name.  Calling [file].getName() gives the same result for all of
> > them.  I don't think there is a way to get a full name from the
> > browsers that send only the file name.  There is no reason, of course,
> > to know the full name.
> >
> > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> >
> >>It seems to me a method to get JUST the filename makes a lot of sense...
> >>what has been the reason for not adding it IN ADDITION to what's there
> >>now?  Unfortunately it would make more sense if getName() returned just
> >>the name while there was another method, maybe getFullName() that
> >>returned what getName() returns now, but that breaks existing code
> >>potentially, so I can certainly see why that hasn't been done, but
> >>adding something like getJustTheName() or something (obviously there
> >>must be a better choice!) makes sense to me.
> >>
> >>Frank
> >>
> >>Dakota Jack wrote:
> >>
> >>>That is an excellent point, Robert.  I often forget how horrible it
> >>>must be to be immeshed in those programming worlds where there is no
> >>>recourse.  Too often we shy away, I think, at changing code, even with
> >>>the Java distribution itself, license issues notwithstanding.
> >>>
> >>>On 5/4/05, robert burrell donkin <[hidden email]>
wrote:

> >>>
> >>>
> >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> >>>>
> >>>>
> >>>>>Some people think this is a bug and some people think that this is a
> >>>>>feature.
> >>>>
> >>>><snip>
> >>>>
> >>>>>That is not a problem, however.  I just went in and changed the
> >>>>>commons upload code adding .getName() to the file at this stage.  The
> >>>>>problem you are seeing is in Internet Explorer, right?  Firefox and
> >>>>>Netscape return the file name and Internet Explorer returns the full
> >>>>>path.  Anyway, you either have to solve the problem in the commons
> >>>>>upload code itself, where it is easy to solve, or to go through some
> >>>>>wasted mechanisms after the fact.  Everyone has to solve this problem
> >>>>>somewhere, so I definitely come down on the side of "bug" versus
> >>>>>"feature".
> >>>>
> >>>>the great thing about open source is that you are free to do exactly
> >>>>this :)
> >>>>
> >>>>- robert

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
Just so there is no misunderstanding, the browsers have nothing to do
with what getName returns.  The browsers differ in what name they
provide for the file.  Thus, when you get a File object for IE it
gives the full name and for the others the actual file name itself.
You make them all the same if you change commonsupload to give you
file,getName() rather than just file.



    // Just add this to the "protected String getFileName(Map
headers)" method in FileUploadBase
    if(fileName != null) {
      fileName = new java.io.File(fileName).getName();
    }



On 5/5/05, Mihael Knezevic <[hidden email]> wrote:

> thanks to all the responses for my question.
>
> actually i didn't know that it was a browser "thing". i thought it was an
> operating system thing. thanks for clearing this up. and as this is a browser
> specific thing IMHO there should be just a change in the docu where you
> should add the fact that the IE is not behaving like any other browser with
> the method getName. that would be of much help.
>
> and this is the kind of "feature" i don't like of MS software.
>
> Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > I know, I've run into this myself... But, it should be a fairly trivial
> > exercise to write code to extract just the filename (as I believe you've
> > done).  This makes sense to me as an additional method.  That way no
> > existing code gets broken, but newer code can use the new method, which
> > works as getName() probably should have been working all along anyway
> > (IMHO).
> >
> > Frank
> >
> > Dakota Jack wrote:
> > > The data difference is not in the code but in the request data from
> > > the browser.  IE puts in the full name and other browsers put in just
> > > the name.  Calling [file].getName() gives the same result for all of
> > > them.  I don't think there is a way to get a full name from the
> > > browsers that send only the file name.  There is no reason, of course,
> > > to know the full name.
> > >
> > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > >
> > >>It seems to me a method to get JUST the filename makes a lot of sense...
> > >>what has been the reason for not adding it IN ADDITION to what's there
> > >>now?  Unfortunately it would make more sense if getName() returned just
> > >>the name while there was another method, maybe getFullName() that
> > >>returned what getName() returns now, but that breaks existing code
> > >>potentially, so I can certainly see why that hasn't been done, but
> > >>adding something like getJustTheName() or something (obviously there
> > >>must be a better choice!) makes sense to me.
> > >>
> > >>Frank
> > >>
> > >>Dakota Jack wrote:
> > >>
> > >>>That is an excellent point, Robert.  I often forget how horrible it
> > >>>must be to be immeshed in those programming worlds where there is no
> > >>>recourse.  Too often we shy away, I think, at changing code, even with
> > >>>the Java distribution itself, license issues notwithstanding.
> > >>>
> > >>>On 5/4/05, robert burrell donkin <[hidden email]>
> wrote:
> > >>>
> > >>>
> > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > >>>>
> > >>>>
> > >>>>>Some people think this is a bug and some people think that this is a
> > >>>>>feature.
> > >>>>
> > >>>><snip>
> > >>>>
> > >>>>>That is not a problem, however.  I just went in and changed the
> > >>>>>commons upload code adding .getName() to the file at this stage.  The
> > >>>>>problem you are seeing is in Internet Explorer, right?  Firefox and
> > >>>>>Netscape return the file name and Internet Explorer returns the full
> > >>>>>path.  Anyway, you either have to solve the problem in the commons
> > >>>>>upload code itself, where it is easy to solve, or to go through some
> > >>>>>wasted mechanisms after the fact.  Everyone has to solve this problem
> > >>>>>somewhere, so I definitely come down on the side of "bug" versus
> > >>>>>"feature".
> > >>>>
> > >>>>the great thing about open source is that you are free to do exactly
> > >>>>this :)
> > >>>>
> > >>>>- robert
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: [FileUpload] Getting wrong filename from FileItem

Knezevic, Mihael
In reply to this post by Knezevic, Mihael
 

> -----Ursprüngliche Nachricht-----
> Von: Dakota Jack [mailto:[hidden email]]
> Gesendet: Freitag, 6. Mai 2005 08:51
> An: Jakarta Commons Users List; Knezevic, Mihael
> Betreff: Re: [FileUpload] Getting wrong filename from FileItem
>
> Just so there is no misunderstanding, the browsers have
> nothing to do with what getName returns.  The browsers differ
> in what name they provide for the file.  Thus, when you get a
> File object for IE it gives the full name and for the others
> the actual file name itself.
thanks for the extra explanation. it's what i understood in the first place (no offense on this one).


> You make them all the same if you change commonsupload to give you
> file,getName() rather than just file.
>
>
>
>     // Just add this to the "protected String getFileName(Map
> headers)" method in FileUploadBase
>     if(fileName != null) {
>       fileName = new java.io.File(fileName).getName();
>     }

tried that in the first place in my programm. but as the filename is something like C:\mydir\myfile.txt (windows file path) it doesn't seem to work on the linux server i'm running. file separators are different. correct me if i'm wrong.

windows client (ie) returns C:\mydir\myfile.txt to my linux server. on linux the file separator is a slash ( / ) and not a backslash ( \ ). so my linux server searches for a slash in the full filename to get just the filename. but there is none. so it assumes it is the filename and returns it all.

>
>
> On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > thanks to all the responses for my question.
> >
> > actually i didn't know that it was a browser "thing". i
> thought it was
> > an operating system thing. thanks for clearing this up. and
> as this is
> > a browser specific thing IMHO there should be just a change in the
> > docu where you should add the fact that the IE is not behaving like
> > any other browser with the method getName. that would be of
> much help.
> >
> > and this is the kind of "feature" i don't like of MS software.
> >
> > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > I know, I've run into this myself... But, it should be a fairly
> > > trivial exercise to write code to extract just the filename (as I
> > > believe you've done).  This makes sense to me as an additional
> > > method.  That way no existing code gets broken, but newer
> code can
> > > use the new method, which works as getName() probably should have
> > > been working all along anyway (IMHO).
> > >
> > > Frank
> > >
> > > Dakota Jack wrote:
> > > > The data difference is not in the code but in the request data
> > > > from the browser.  IE puts in the full name and other
> browsers put
> > > > in just the name.  Calling [file].getName() gives the
> same result
> > > > for all of them.  I don't think there is a way to get a
> full name
> > > > from the browsers that send only the file name.  There is no
> > > > reason, of course, to know the full name.
> > > >
> > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > >
> > > >>It seems to me a method to get JUST the filename makes
> a lot of sense...
> > > >>what has been the reason for not adding it IN ADDITION
> to what's
> > > >>there now?  Unfortunately it would make more sense if getName()
> > > >>returned just the name while there was another method, maybe
> > > >>getFullName() that returned what getName() returns now,
> but that
> > > >>breaks existing code potentially, so I can certainly
> see why that
> > > >>hasn't been done, but adding something like getJustTheName() or
> > > >>something (obviously there must be a better choice!)
> makes sense to me.
> > > >>
> > > >>Frank
> > > >>
> > > >>Dakota Jack wrote:
> > > >>
> > > >>>That is an excellent point, Robert.  I often forget
> how horrible
> > > >>>it must be to be immeshed in those programming worlds
> where there
> > > >>>is no recourse.  Too often we shy away, I think, at changing
> > > >>>code, even with the Java distribution itself, license
> issues notwithstanding.
> > > >>>
> > > >>>On 5/4/05, robert burrell donkin
> > > >>><[hidden email]>
> > wrote:
> > > >>>
> > > >>>
> > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > >>>>
> > > >>>>
> > > >>>>>Some people think this is a bug and some people
> think that this
> > > >>>>>is a feature.
> > > >>>>
> > > >>>><snip>
> > > >>>>
> > > >>>>>That is not a problem, however.  I just went in and
> changed the
> > > >>>>>commons upload code adding .getName() to the file at this
> > > >>>>>stage.  The problem you are seeing is in Internet Explorer,
> > > >>>>>right?  Firefox and Netscape return the file name
> and Internet
> > > >>>>>Explorer returns the full path.  Anyway, you either have to
> > > >>>>>solve the problem in the commons upload code itself,
> where it
> > > >>>>>is easy to solve, or to go through some wasted
> mechanisms after
> > > >>>>>the fact.  Everyone has to solve this problem
> somewhere, so I
> > > >>>>>definitely come down on the side of "bug" versus "feature".
> > > >>>>
> > > >>>>the great thing about open source is that you are free to do
> > > >>>>exactly this :)
> > > >>>>
> > > >>>>- robert
> >

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
In File there is a field of separator which is good on whatever
platform you are running.  If you construct paths, to make your code
portable, use File.separator instead of / or \.  The other parts of a
path are also fields in File.  So, there should be no problem with
this.

No offence taken.

On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:

>
>
> > -----Ursprüngliche Nachricht-----
> > Von: Dakota Jack [mailto:[hidden email]]
> > Gesendet: Freitag, 6. Mai 2005 08:51
> > An: Jakarta Commons Users List; Knezevic, Mihael
> > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> >
> > Just so there is no misunderstanding, the browsers have
> > nothing to do with what getName returns.  The browsers differ
> > in what name they provide for the file.  Thus, when you get a
> > File object for IE it gives the full name and for the others
> > the actual file name itself.
> thanks for the extra explanation. it's what i understood in the first place (no offense on this one).
>
>
> > You make them all the same if you change commonsupload to give you
> > file,getName() rather than just file.
> >
> >
> >
> >     // Just add this to the "protected String getFileName(Map
> > headers)" method in FileUploadBase
> >     if(fileName != null) {
> >       fileName = new java.io.File(fileName).getName();
> >     }
>
> tried that in the first place in my programm. but as the filename is something like C:\mydir\myfile.txt (windows file path) it doesn't seem to work on the linux server i'm running. file separators are different. correct me if i'm wrong.
>
> windows client (ie) returns C:\mydir\myfile.txt to my linux server. on linux the file separator is a slash ( / ) and not a backslash ( \ ). so my linux server searches for a slash in the full filename to get just the filename. but there is none. so it assumes it is the filename and returns it all.
>
> >
> >
> > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > thanks to all the responses for my question.
> > >
> > > actually i didn't know that it was a browser "thing". i
> > thought it was
> > > an operating system thing. thanks for clearing this up. and
> > as this is
> > > a browser specific thing IMHO there should be just a change in the
> > > docu where you should add the fact that the IE is not behaving like
> > > any other browser with the method getName. that would be of
> > much help.
> > >
> > > and this is the kind of "feature" i don't like of MS software.
> > >
> > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > I know, I've run into this myself... But, it should be a fairly
> > > > trivial exercise to write code to extract just the filename (as I
> > > > believe you've done).  This makes sense to me as an additional
> > > > method.  That way no existing code gets broken, but newer
> > code can
> > > > use the new method, which works as getName() probably should have
> > > > been working all along anyway (IMHO).
> > > >
> > > > Frank
> > > >
> > > > Dakota Jack wrote:
> > > > > The data difference is not in the code but in the request data
> > > > > from the browser.  IE puts in the full name and other
> > browsers put
> > > > > in just the name.  Calling [file].getName() gives the
> > same result
> > > > > for all of them.  I don't think there is a way to get a
> > full name
> > > > > from the browsers that send only the file name.  There is no
> > > > > reason, of course, to know the full name.
> > > > >
> > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > >
> > > > >>It seems to me a method to get JUST the filename makes
> > a lot of sense...
> > > > >>what has been the reason for not adding it IN ADDITION
> > to what's
> > > > >>there now?  Unfortunately it would make more sense if getName()
> > > > >>returned just the name while there was another method, maybe
> > > > >>getFullName() that returned what getName() returns now,
> > but that
> > > > >>breaks existing code potentially, so I can certainly
> > see why that
> > > > >>hasn't been done, but adding something like getJustTheName() or
> > > > >>something (obviously there must be a better choice!)
> > makes sense to me.
> > > > >>
> > > > >>Frank
> > > > >>
> > > > >>Dakota Jack wrote:
> > > > >>
> > > > >>>That is an excellent point, Robert.  I often forget
> > how horrible
> > > > >>>it must be to be immeshed in those programming worlds
> > where there
> > > > >>>is no recourse.  Too often we shy away, I think, at changing
> > > > >>>code, even with the Java distribution itself, license
> > issues notwithstanding.
> > > > >>>
> > > > >>>On 5/4/05, robert burrell donkin
> > > > >>><[hidden email]>
> > > wrote:
> > > > >>>
> > > > >>>
> > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > >>>>
> > > > >>>>
> > > > >>>>>Some people think this is a bug and some people
> > think that this
> > > > >>>>>is a feature.
> > > > >>>>
> > > > >>>><snip>
> > > > >>>>
> > > > >>>>>That is not a problem, however.  I just went in and
> > changed the
> > > > >>>>>commons upload code adding .getName() to the file at this
> > > > >>>>>stage.  The problem you are seeing is in Internet Explorer,
> > > > >>>>>right?  Firefox and Netscape return the file name
> > and Internet
> > > > >>>>>Explorer returns the full path.  Anyway, you either have to
> > > > >>>>>solve the problem in the commons upload code itself,
> > where it
> > > > >>>>>is easy to solve, or to go through some wasted
> > mechanisms after
> > > > >>>>>the fact.  Everyone has to solve this problem
> > somewhere, so I
> > > > >>>>>definitely come down on the side of "bug" versus "feature".
> > > > >>>>
> > > > >>>>the great thing about open source is that you are free to do
> > > > >>>>exactly this :)
> > > > >>>>
> > > > >>>>- robert
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
In reply to this post by Knezevic, Mihael
This code should definitely work.  If it does not, I sure would like
to know what happens.  What did happen?  Did you debug it?



On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:

>
>
> > -----Ursprüngliche Nachricht-----
> > Von: Dakota Jack [mailto:[hidden email]]
> > Gesendet: Freitag, 6. Mai 2005 08:51
> > An: Jakarta Commons Users List; Knezevic, Mihael
> > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> >
> > Just so there is no misunderstanding, the browsers have
> > nothing to do with what getName returns.  The browsers differ
> > in what name they provide for the file.  Thus, when you get a
> > File object for IE it gives the full name and for the others
> > the actual file name itself.
> thanks for the extra explanation. it's what i understood in the first place (no offense on this one).
>
>
> > You make them all the same if you change commonsupload to give you
> > file,getName() rather than just file.
> >
> >
> >
> >     // Just add this to the "protected String getFileName(Map
> > headers)" method in FileUploadBase
> >     if(fileName != null) {
> >       fileName = new java.io.File(fileName).getName();
> >     }
>
> tried that in the first place in my programm. but as the filename is something like C:\mydir\myfile.txt (windows file path) it doesn't seem to work on the linux server i'm running. file separators are different. correct me if i'm wrong.
>
> windows client (ie) returns C:\mydir\myfile.txt to my linux server. on linux the file separator is a slash ( / ) and not a backslash ( \ ). so my linux server searches for a slash in the full filename to get just the filename. but there is none. so it assumes it is the filename and returns it all.
>
> >
> >
> > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > thanks to all the responses for my question.
> > >
> > > actually i didn't know that it was a browser "thing". i
> > thought it was
> > > an operating system thing. thanks for clearing this up. and
> > as this is
> > > a browser specific thing IMHO there should be just a change in the
> > > docu where you should add the fact that the IE is not behaving like
> > > any other browser with the method getName. that would be of
> > much help.
> > >
> > > and this is the kind of "feature" i don't like of MS software.
> > >
> > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > I know, I've run into this myself... But, it should be a fairly
> > > > trivial exercise to write code to extract just the filename (as I
> > > > believe you've done).  This makes sense to me as an additional
> > > > method.  That way no existing code gets broken, but newer
> > code can
> > > > use the new method, which works as getName() probably should have
> > > > been working all along anyway (IMHO).
> > > >
> > > > Frank
> > > >
> > > > Dakota Jack wrote:
> > > > > The data difference is not in the code but in the request data
> > > > > from the browser.  IE puts in the full name and other
> > browsers put
> > > > > in just the name.  Calling [file].getName() gives the
> > same result
> > > > > for all of them.  I don't think there is a way to get a
> > full name
> > > > > from the browsers that send only the file name.  There is no
> > > > > reason, of course, to know the full name.
> > > > >
> > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > >
> > > > >>It seems to me a method to get JUST the filename makes
> > a lot of sense...
> > > > >>what has been the reason for not adding it IN ADDITION
> > to what's
> > > > >>there now?  Unfortunately it would make more sense if getName()
> > > > >>returned just the name while there was another method, maybe
> > > > >>getFullName() that returned what getName() returns now,
> > but that
> > > > >>breaks existing code potentially, so I can certainly
> > see why that
> > > > >>hasn't been done, but adding something like getJustTheName() or
> > > > >>something (obviously there must be a better choice!)
> > makes sense to me.
> > > > >>
> > > > >>Frank
> > > > >>
> > > > >>Dakota Jack wrote:
> > > > >>
> > > > >>>That is an excellent point, Robert.  I often forget
> > how horrible
> > > > >>>it must be to be immeshed in those programming worlds
> > where there
> > > > >>>is no recourse.  Too often we shy away, I think, at changing
> > > > >>>code, even with the Java distribution itself, license
> > issues notwithstanding.
> > > > >>>
> > > > >>>On 5/4/05, robert burrell donkin
> > > > >>><[hidden email]>
> > > wrote:
> > > > >>>
> > > > >>>
> > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > >>>>
> > > > >>>>
> > > > >>>>>Some people think this is a bug and some people
> > think that this
> > > > >>>>>is a feature.
> > > > >>>>
> > > > >>>><snip>
> > > > >>>>
> > > > >>>>>That is not a problem, however.  I just went in and
> > changed the
> > > > >>>>>commons upload code adding .getName() to the file at this
> > > > >>>>>stage.  The problem you are seeing is in Internet Explorer,
> > > > >>>>>right?  Firefox and Netscape return the file name
> > and Internet
> > > > >>>>>Explorer returns the full path.  Anyway, you either have to
> > > > >>>>>solve the problem in the commons upload code itself,
> > where it
> > > > >>>>>is easy to solve, or to go through some wasted
> > mechanisms after
> > > > >>>>>the fact.  Everyone has to solve this problem
> > somewhere, so I
> > > > >>>>>definitely come down on the side of "bug" versus "feature".
> > > > >>>>
> > > > >>>>the great thing about open source is that you are free to do
> > > > >>>>exactly this :)
> > > > >>>>
> > > > >>>>- robert
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: [FileUpload] Getting wrong filename from FileItem

Knezevic, Mihael
In reply to this post by Knezevic, Mihael
i can not figure out how this should work. this is a web application. linux and windows clients are accessing the app. the filename can be /mydir/myfile.txt and C:\mydir\myfile.txt. how should the server know which file separator to use. hmm. i could take a look at the http request data. ain't there a field for the operating system. but that ain't something i like to do. these things are always changing.

i'll try your code later. thanks.

> -----Ursprüngliche Nachricht-----
> Von: Dakota Jack [mailto:[hidden email]]
> Gesendet: Freitag, 6. Mai 2005 09:34
> An: Jakarta Commons Users List
> Betreff: Re: [FileUpload] Getting wrong filename from FileItem
>
> This code should definitely work.  If it does not, I sure
> would like to know what happens.  What did happen?  Did you debug it?
>
>
>
> On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> >
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Dakota Jack [mailto:[hidden email]]
> > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > >
> > > Just so there is no misunderstanding, the browsers have
> nothing to
> > > do with what getName returns.  The browsers differ in
> what name they
> > > provide for the file.  Thus, when you get a File object for IE it
> > > gives the full name and for the others the actual file
> name itself.
> > thanks for the extra explanation. it's what i understood in
> the first place (no offense on this one).
> >
> >
> > > You make them all the same if you change commonsupload to give you
> > > file,getName() rather than just file.
> > >
> > >
> > >
> > >     // Just add this to the "protected String getFileName(Map
> > > headers)" method in FileUploadBase
> > >     if(fileName != null) {
> > >       fileName = new java.io.File(fileName).getName();
> > >     }
> >
> > tried that in the first place in my programm. but as the
> filename is something like C:\mydir\myfile.txt (windows file
> path) it doesn't seem to work on the linux server i'm
> running. file separators are different. correct me if i'm wrong.
> >
> > windows client (ie) returns C:\mydir\myfile.txt to my linux
> server. on linux the file separator is a slash ( / ) and not
> a backslash ( \ ). so my linux server searches for a slash in
> the full filename to get just the filename. but there is
> none. so it assumes it is the filename and returns it all.
> >
> > >
> > >
> > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > thanks to all the responses for my question.
> > > >
> > > > actually i didn't know that it was a browser "thing". i
> > > thought it was
> > > > an operating system thing. thanks for clearing this up. and
> > > as this is
> > > > a browser specific thing IMHO there should be just a
> change in the
> > > > docu where you should add the fact that the IE is not behaving
> > > > like any other browser with the method getName. that would be of
> > > much help.
> > > >
> > > > and this is the kind of "feature" i don't like of MS software.
> > > >
> > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > I know, I've run into this myself... But, it should
> be a fairly
> > > > > trivial exercise to write code to extract just the
> filename (as
> > > > > I believe you've done).  This makes sense to me as an
> additional
> > > > > method.  That way no existing code gets broken, but newer
> > > code can
> > > > > use the new method, which works as getName() probably should
> > > > > have been working all along anyway (IMHO).
> > > > >
> > > > > Frank
> > > > >
> > > > > Dakota Jack wrote:
> > > > > > The data difference is not in the code but in the
> request data
> > > > > > from the browser.  IE puts in the full name and other
> > > browsers put
> > > > > > in just the name.  Calling [file].getName() gives the
> > > same result
> > > > > > for all of them.  I don't think there is a way to get a
> > > full name
> > > > > > from the browsers that send only the file name.  
> There is no
> > > > > > reason, of course, to know the full name.
> > > > > >
> > > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > > >
> > > > > >>It seems to me a method to get JUST the filename makes
> > > a lot of sense...
> > > > > >>what has been the reason for not adding it IN ADDITION
> > > to what's
> > > > > >>there now?  Unfortunately it would make more sense if
> > > > > >>getName() returned just the name while there was another
> > > > > >>method, maybe
> > > > > >>getFullName() that returned what getName() returns now,
> > > but that
> > > > > >>breaks existing code potentially, so I can certainly
> > > see why that
> > > > > >>hasn't been done, but adding something like
> getJustTheName()
> > > > > >>or something (obviously there must be a better choice!)
> > > makes sense to me.
> > > > > >>
> > > > > >>Frank
> > > > > >>
> > > > > >>Dakota Jack wrote:
> > > > > >>
> > > > > >>>That is an excellent point, Robert.  I often forget
> > > how horrible
> > > > > >>>it must be to be immeshed in those programming worlds
> > > where there
> > > > > >>>is no recourse.  Too often we shy away, I think,
> at changing
> > > > > >>>code, even with the Java distribution itself, license
> > > issues notwithstanding.
> > > > > >>>
> > > > > >>>On 5/4/05, robert burrell donkin
> > > > > >>><[hidden email]>
> > > > wrote:
> > > > > >>>
> > > > > >>>
> > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > >>>>
> > > > > >>>>
> > > > > >>>>>Some people think this is a bug and some people
> > > think that this
> > > > > >>>>>is a feature.
> > > > > >>>>
> > > > > >>>><snip>
> > > > > >>>>
> > > > > >>>>>That is not a problem, however.  I just went in and
> > > changed the
> > > > > >>>>>commons upload code adding .getName() to the
> file at this
> > > > > >>>>>stage.  The problem you are seeing is in
> Internet Explorer,
> > > > > >>>>>right?  Firefox and Netscape return the file name
> > > and Internet
> > > > > >>>>>Explorer returns the full path.  Anyway, you
> either have to
> > > > > >>>>>solve the problem in the commons upload code itself,
> > > where it
> > > > > >>>>>is easy to solve, or to go through some wasted
> > > mechanisms after
> > > > > >>>>>the fact.  Everyone has to solve this problem
> > > somewhere, so I
> > > > > >>>>>definitely come down on the side of "bug" versus
> "feature".
> > > > > >>>>
> > > > > >>>>the great thing about open source is that you are
> free to do
> > > > > >>>>exactly this :)
> > > > > >>>>
> > > > > >>>>- robert
> > > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail:
> [hidden email]
> >
> >
>
>
> --
> "You can lead a horse to water but you cannot make it float
> on its back."
> ~Dakota Jack~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
I tested it out on both file separators (linux and microsoft) and it
works on both.  Just run a test and see if it works.  It does


public class Test {
  public static void main(String [] params) {
    File ie = new File("C:\\mydir\\myfile.txt");
    File linux = new File("/mydir/myfile.txt");
    StdOut.log("log.development","Test ttf ie.getName() = " + ie.getName());
    StdOut.log("log.development","Test ttf linux.getName() = " +
linux.getName());
}

You should just use System.out.println() of course.


On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:

> i can not figure out how this should work. this is a web application. linux and windows clients are accessing the app. the filename can be /mydir/myfile.txt and C:\mydir\myfile.txt. how should the server know which file separator to use. hmm. i could take a look at the http request data. ain't there a field for the operating system. but that ain't something i like to do. these things are always changing.
>
> i'll try your code later. thanks.
>
> > -----Ursprüngliche Nachricht-----
> > Von: Dakota Jack [mailto:[hidden email]]
> > Gesendet: Freitag, 6. Mai 2005 09:34
> > An: Jakarta Commons Users List
> > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> >
> > This code should definitely work.  If it does not, I sure
> > would like to know what happens.  What did happen?  Did you debug it?
> >
> >
> >
> > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > >
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > >
> > > > Just so there is no misunderstanding, the browsers have
> > nothing to
> > > > do with what getName returns.  The browsers differ in
> > what name they
> > > > provide for the file.  Thus, when you get a File object for IE it
> > > > gives the full name and for the others the actual file
> > name itself.
> > > thanks for the extra explanation. it's what i understood in
> > the first place (no offense on this one).
> > >
> > >
> > > > You make them all the same if you change commonsupload to give you
> > > > file,getName() rather than just file.
> > > >
> > > >
> > > >
> > > >     // Just add this to the "protected String getFileName(Map
> > > > headers)" method in FileUploadBase
> > > >     if(fileName != null) {
> > > >       fileName = new java.io.File(fileName).getName();
> > > >     }
> > >
> > > tried that in the first place in my programm. but as the
> > filename is something like C:\mydir\myfile.txt (windows file
> > path) it doesn't seem to work on the linux server i'm
> > running. file separators are different. correct me if i'm wrong.
> > >
> > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > server. on linux the file separator is a slash ( / ) and not
> > a backslash ( \ ). so my linux server searches for a slash in
> > the full filename to get just the filename. but there is
> > none. so it assumes it is the filename and returns it all.
> > >
> > > >
> > > >
> > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > thanks to all the responses for my question.
> > > > >
> > > > > actually i didn't know that it was a browser "thing". i
> > > > thought it was
> > > > > an operating system thing. thanks for clearing this up. and
> > > > as this is
> > > > > a browser specific thing IMHO there should be just a
> > change in the
> > > > > docu where you should add the fact that the IE is not behaving
> > > > > like any other browser with the method getName. that would be of
> > > > much help.
> > > > >
> > > > > and this is the kind of "feature" i don't like of MS software.
> > > > >
> > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > I know, I've run into this myself... But, it should
> > be a fairly
> > > > > > trivial exercise to write code to extract just the
> > filename (as
> > > > > > I believe you've done).  This makes sense to me as an
> > additional
> > > > > > method.  That way no existing code gets broken, but newer
> > > > code can
> > > > > > use the new method, which works as getName() probably should
> > > > > > have been working all along anyway (IMHO).
> > > > > >
> > > > > > Frank
> > > > > >
> > > > > > Dakota Jack wrote:
> > > > > > > The data difference is not in the code but in the
> > request data
> > > > > > > from the browser.  IE puts in the full name and other
> > > > browsers put
> > > > > > > in just the name.  Calling [file].getName() gives the
> > > > same result
> > > > > > > for all of them.  I don't think there is a way to get a
> > > > full name
> > > > > > > from the browsers that send only the file name.
> > There is no
> > > > > > > reason, of course, to know the full name.
> > > > > > >
> > > > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > > > >
> > > > > > >>It seems to me a method to get JUST the filename makes
> > > > a lot of sense...
> > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > to what's
> > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > >>getName() returned just the name while there was another
> > > > > > >>method, maybe
> > > > > > >>getFullName() that returned what getName() returns now,
> > > > but that
> > > > > > >>breaks existing code potentially, so I can certainly
> > > > see why that
> > > > > > >>hasn't been done, but adding something like
> > getJustTheName()
> > > > > > >>or something (obviously there must be a better choice!)
> > > > makes sense to me.
> > > > > > >>
> > > > > > >>Frank
> > > > > > >>
> > > > > > >>Dakota Jack wrote:
> > > > > > >>
> > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > how horrible
> > > > > > >>>it must be to be immeshed in those programming worlds
> > > > where there
> > > > > > >>>is no recourse.  Too often we shy away, I think,
> > at changing
> > > > > > >>>code, even with the Java distribution itself, license
> > > > issues notwithstanding.
> > > > > > >>>
> > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > >>><[hidden email]>
> > > > > wrote:
> > > > > > >>>
> > > > > > >>>
> > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > >>>>
> > > > > > >>>>
> > > > > > >>>>>Some people think this is a bug and some people
> > > > think that this
> > > > > > >>>>>is a feature.
> > > > > > >>>>
> > > > > > >>>><snip>
> > > > > > >>>>
> > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > changed the
> > > > > > >>>>>commons upload code adding .getName() to the
> > file at this
> > > > > > >>>>>stage.  The problem you are seeing is in
> > Internet Explorer,
> > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > and Internet
> > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > either have to
> > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > where it
> > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > mechanisms after
> > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > somewhere, so I
> > > > > > >>>>>definitely come down on the side of "bug" versus
> > "feature".
> > > > > > >>>>
> > > > > > >>>>the great thing about open source is that you are
> > free to do
> > > > > > >>>>exactly this :)
> > > > > > >>>>
> > > > > > >>>>- robert
> > > > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail:
> > [hidden email]
> > >
> > >
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float
> > on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: [FileUpload] Getting wrong filename from FileItem

Knezevic, Mihael
In reply to this post by Knezevic, Mihael
thanks for all the advice. i'll test it.

> -----Ursprüngliche Nachricht-----
> Von: Dakota Jack [mailto:[hidden email]]
> Gesendet: Freitag, 6. Mai 2005 09:55
> An: Jakarta Commons Users List
> Betreff: Re: [FileUpload] Getting wrong filename from FileItem
>
> I tested it out on both file separators (linux and microsoft)
> and it works on both.  Just run a test and see if it works.  It does
>
>
> public class Test {
>   public static void main(String [] params) {
>     File ie = new File("C:\\mydir\\myfile.txt");
>     File linux = new File("/mydir/myfile.txt");
>     StdOut.log("log.development","Test ttf ie.getName() = " +
> ie.getName());
>     StdOut.log("log.development","Test ttf linux.getName() =
> " + linux.getName()); }
>
> You should just use System.out.println() of course.
>
>
> On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > i can not figure out how this should work. this is a web
> application. linux and windows clients are accessing the app.
> the filename can be /mydir/myfile.txt and
> C:\mydir\myfile.txt. how should the server know which file
> separator to use. hmm. i could take a look at the http
> request data. ain't there a field for the operating system.
> but that ain't something i like to do. these things are
> always changing.
> >
> > i'll try your code later. thanks.
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Dakota Jack [mailto:[hidden email]]
> > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > An: Jakarta Commons Users List
> > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > >
> > > This code should definitely work.  If it does not, I sure
> would like
> > > to know what happens.  What did happen?  Did you debug it?
> > >
> > >
> > >
> > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > >
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > >
> > > > > Just so there is no misunderstanding, the browsers have
> > > nothing to
> > > > > do with what getName returns.  The browsers differ in
> > > what name they
> > > > > provide for the file.  Thus, when you get a File
> object for IE
> > > > > it gives the full name and for the others the actual file
> > > name itself.
> > > > thanks for the extra explanation. it's what i understood in
> > > the first place (no offense on this one).
> > > >
> > > >
> > > > > You make them all the same if you change
> commonsupload to give
> > > > > you
> > > > > file,getName() rather than just file.
> > > > >
> > > > >
> > > > >
> > > > >     // Just add this to the "protected String getFileName(Map
> > > > > headers)" method in FileUploadBase
> > > > >     if(fileName != null) {
> > > > >       fileName = new java.io.File(fileName).getName();
> > > > >     }
> > > >
> > > > tried that in the first place in my programm. but as the
> > > filename is something like C:\mydir\myfile.txt (windows file
> > > path) it doesn't seem to work on the linux server i'm
> running. file
> > > separators are different. correct me if i'm wrong.
> > > >
> > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > server. on linux the file separator is a slash ( / ) and not a
> > > backslash ( \ ). so my linux server searches for a slash
> in the full
> > > filename to get just the filename. but there is none. so
> it assumes
> > > it is the filename and returns it all.
> > > >
> > > > >
> > > > >
> > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > thanks to all the responses for my question.
> > > > > >
> > > > > > actually i didn't know that it was a browser "thing". i
> > > > > thought it was
> > > > > > an operating system thing. thanks for clearing this up. and
> > > > > as this is
> > > > > > a browser specific thing IMHO there should be just a
> > > change in the
> > > > > > docu where you should add the fact that the IE is
> not behaving
> > > > > > like any other browser with the method getName.
> that would be
> > > > > > of
> > > > > much help.
> > > > > >
> > > > > > and this is the kind of "feature" i don't like of
> MS software.
> > > > > >
> > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > I know, I've run into this myself... But, it should
> > > be a fairly
> > > > > > > trivial exercise to write code to extract just the
> > > filename (as
> > > > > > > I believe you've done).  This makes sense to me as an
> > > additional
> > > > > > > method.  That way no existing code gets broken, but newer
> > > > > code can
> > > > > > > use the new method, which works as getName()
> probably should
> > > > > > > have been working all along anyway (IMHO).
> > > > > > >
> > > > > > > Frank
> > > > > > >
> > > > > > > Dakota Jack wrote:
> > > > > > > > The data difference is not in the code but in the
> > > request data
> > > > > > > > from the browser.  IE puts in the full name and other
> > > > > browsers put
> > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > same result
> > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > full name
> > > > > > > > from the browsers that send only the file name.
> > > There is no
> > > > > > > > reason, of course, to know the full name.
> > > > > > > >
> > > > > > > > On 5/4/05, Frank W. Zammetti
> <[hidden email]> wrote:
> > > > > > > >
> > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > a lot of sense...
> > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > to what's
> > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > >>getName() returned just the name while there
> was another
> > > > > > > >>method, maybe
> > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > but that
> > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > see why that
> > > > > > > >>hasn't been done, but adding something like
> > > getJustTheName()
> > > > > > > >>or something (obviously there must be a better choice!)
> > > > > makes sense to me.
> > > > > > > >>
> > > > > > > >>Frank
> > > > > > > >>
> > > > > > > >>Dakota Jack wrote:
> > > > > > > >>
> > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > how horrible
> > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > where there
> > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > at changing
> > > > > > > >>>code, even with the Java distribution itself, license
> > > > > issues notwithstanding.
> > > > > > > >>>
> > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > >>><[hidden email]>
> > > > > > wrote:
> > > > > > > >>>
> > > > > > > >>>
> > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>>>Some people think this is a bug and some people
> > > > > think that this
> > > > > > > >>>>>is a feature.
> > > > > > > >>>>
> > > > > > > >>>><snip>
> > > > > > > >>>>
> > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > changed the
> > > > > > > >>>>>commons upload code adding .getName() to the
> > > file at this
> > > > > > > >>>>>stage.  The problem you are seeing is in
> > > Internet Explorer,
> > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > and Internet
> > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > either have to
> > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > where it
> > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > mechanisms after
> > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > somewhere, so I
> > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > "feature".
> > > > > > > >>>>
> > > > > > > >>>>the great thing about open source is that you are
> > > free to do
> > > > > > > >>>>exactly this :)
> > > > > > > >>>>
> > > > > > > >>>>- robert
> > > > > >
> > > >
> > > >
> > >
> --------------------------------------------------------------------
> > > -
> > > > To unsubscribe, e-mail:
> > > > [hidden email]
> > > > For additional commands, e-mail:
> > > [hidden email]
> > > >
> > > >
> > >
> > >
> > > --
> > > "You can lead a horse to water but you cannot make it
> float on its
> > > back."
> > > ~Dakota Jack~
> > >
> > >
> --------------------------------------------------------------------
> > > - To unsubscribe, e-mail:
> > > [hidden email]
> > > For additional commands, e-mail:
> > > [hidden email]
> > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail:
> [hidden email]
> >
> >
>
>
> --
> "You can lead a horse to water but you cannot make it float
> on its back."
> ~Dakota Jack~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
You know, Mihael, the reason it works is that the code is new
File(fileName).getName() so that the creation of the file converts to
the local separator.  Look at the Java source.

You agree?  Anyway, I am probably making the thread too long, but I
like to compete these things.

On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:

> thanks for all the advice. i'll test it.
>
> > -----Ursprüngliche Nachricht-----
> > Von: Dakota Jack [mailto:[hidden email]]
> > Gesendet: Freitag, 6. Mai 2005 09:55
> > An: Jakarta Commons Users List
> > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> >
> > I tested it out on both file separators (linux and microsoft)
> > and it works on both.  Just run a test and see if it works.  It does
> >
> >
> > public class Test {
> >   public static void main(String [] params) {
> >     File ie = new File("C:\\mydir\\myfile.txt");
> >     File linux = new File("/mydir/myfile.txt");
> >     StdOut.log("log.development","Test ttf ie.getName() = " +
> > ie.getName());
> >     StdOut.log("log.development","Test ttf linux.getName() =
> > " + linux.getName()); }
> >
> > You should just use System.out.println() of course.
> >
> >
> > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > i can not figure out how this should work. this is a web
> > application. linux and windows clients are accessing the app.
> > the filename can be /mydir/myfile.txt and
> > C:\mydir\myfile.txt. how should the server know which file
> > separator to use. hmm. i could take a look at the http
> > request data. ain't there a field for the operating system.
> > but that ain't something i like to do. these things are
> > always changing.
> > >
> > > i'll try your code later. thanks.
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > > An: Jakarta Commons Users List
> > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > >
> > > > This code should definitely work.  If it does not, I sure
> > would like
> > > > to know what happens.  What did happen?  Did you debug it?
> > > >
> > > >
> > > >
> > > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > >
> > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > > >
> > > > > > Just so there is no misunderstanding, the browsers have
> > > > nothing to
> > > > > > do with what getName returns.  The browsers differ in
> > > > what name they
> > > > > > provide for the file.  Thus, when you get a File
> > object for IE
> > > > > > it gives the full name and for the others the actual file
> > > > name itself.
> > > > > thanks for the extra explanation. it's what i understood in
> > > > the first place (no offense on this one).
> > > > >
> > > > >
> > > > > > You make them all the same if you change
> > commonsupload to give
> > > > > > you
> > > > > > file,getName() rather than just file.
> > > > > >
> > > > > >
> > > > > >
> > > > > >     // Just add this to the "protected String getFileName(Map
> > > > > > headers)" method in FileUploadBase
> > > > > >     if(fileName != null) {
> > > > > >       fileName = new java.io.File(fileName).getName();
> > > > > >     }
> > > > >
> > > > > tried that in the first place in my programm. but as the
> > > > filename is something like C:\mydir\myfile.txt (windows file
> > > > path) it doesn't seem to work on the linux server i'm
> > running. file
> > > > separators are different. correct me if i'm wrong.
> > > > >
> > > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > > server. on linux the file separator is a slash ( / ) and not a
> > > > backslash ( \ ). so my linux server searches for a slash
> > in the full
> > > > filename to get just the filename. but there is none. so
> > it assumes
> > > > it is the filename and returns it all.
> > > > >
> > > > > >
> > > > > >
> > > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > > thanks to all the responses for my question.
> > > > > > >
> > > > > > > actually i didn't know that it was a browser "thing". i
> > > > > > thought it was
> > > > > > > an operating system thing. thanks for clearing this up. and
> > > > > > as this is
> > > > > > > a browser specific thing IMHO there should be just a
> > > > change in the
> > > > > > > docu where you should add the fact that the IE is
> > not behaving
> > > > > > > like any other browser with the method getName.
> > that would be
> > > > > > > of
> > > > > > much help.
> > > > > > >
> > > > > > > and this is the kind of "feature" i don't like of
> > MS software.
> > > > > > >
> > > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > > I know, I've run into this myself... But, it should
> > > > be a fairly
> > > > > > > > trivial exercise to write code to extract just the
> > > > filename (as
> > > > > > > > I believe you've done).  This makes sense to me as an
> > > > additional
> > > > > > > > method.  That way no existing code gets broken, but newer
> > > > > > code can
> > > > > > > > use the new method, which works as getName()
> > probably should
> > > > > > > > have been working all along anyway (IMHO).
> > > > > > > >
> > > > > > > > Frank
> > > > > > > >
> > > > > > > > Dakota Jack wrote:
> > > > > > > > > The data difference is not in the code but in the
> > > > request data
> > > > > > > > > from the browser.  IE puts in the full name and other
> > > > > > browsers put
> > > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > > same result
> > > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > > full name
> > > > > > > > > from the browsers that send only the file name.
> > > > There is no
> > > > > > > > > reason, of course, to know the full name.
> > > > > > > > >
> > > > > > > > > On 5/4/05, Frank W. Zammetti
> > <[hidden email]> wrote:
> > > > > > > > >
> > > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > > a lot of sense...
> > > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > > to what's
> > > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > > >>getName() returned just the name while there
> > was another
> > > > > > > > >>method, maybe
> > > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > > but that
> > > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > > see why that
> > > > > > > > >>hasn't been done, but adding something like
> > > > getJustTheName()
> > > > > > > > >>or something (obviously there must be a better choice!)
> > > > > > makes sense to me.
> > > > > > > > >>
> > > > > > > > >>Frank
> > > > > > > > >>
> > > > > > > > >>Dakota Jack wrote:
> > > > > > > > >>
> > > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > > how horrible
> > > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > > where there
> > > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > > at changing
> > > > > > > > >>>code, even with the Java distribution itself, license
> > > > > > issues notwithstanding.
> > > > > > > > >>>
> > > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > > >>><[hidden email]>
> > > > > > > wrote:
> > > > > > > > >>>
> > > > > > > > >>>
> > > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>>Some people think this is a bug and some people
> > > > > > think that this
> > > > > > > > >>>>>is a feature.
> > > > > > > > >>>>
> > > > > > > > >>>><snip>
> > > > > > > > >>>>
> > > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > > changed the
> > > > > > > > >>>>>commons upload code adding .getName() to the
> > > > file at this
> > > > > > > > >>>>>stage.  The problem you are seeing is in
> > > > Internet Explorer,
> > > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > > and Internet
> > > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > > either have to
> > > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > > where it
> > > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > > mechanisms after
> > > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > > somewhere, so I
> > > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > > "feature".
> > > > > > > > >>>>
> > > > > > > > >>>>the great thing about open source is that you are
> > > > free to do
> > > > > > > > >>>>exactly this :)
> > > > > > > > >>>>
> > > > > > > > >>>>- robert
> > > > > > >
> > > > >
> > > > >
> > > >
> > --------------------------------------------------------------------
> > > > -
> > > > > To unsubscribe, e-mail:
> > > > > [hidden email]
> > > > > For additional commands, e-mail:
> > > > [hidden email]
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > "You can lead a horse to water but you cannot make it
> > float on its
> > > > back."
> > > > ~Dakota Jack~
> > > >
> > > >
> > --------------------------------------------------------------------
> > > > - To unsubscribe, e-mail:
> > > > [hidden email]
> > > > For additional commands, e-mail:
> > > > [hidden email]
> > > >
> > > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail:
> > [hidden email]
> > >
> > >
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float
> > on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
When a FIle object is created with new File([String]), the code in the
constructor calls the local implemenation of FileSystem.java and
normalizes the string to the local file system.



On 5/6/05, Dakota Jack <[hidden email]> wrote:

> You know, Mihael, the reason it works is that the code is new
> File(fileName).getName() so that the creation of the file converts to
> the local separator.  Look at the Java source.
>
> You agree?  Anyway, I am probably making the thread too long, but I
> like to compete these things.
>
> On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > thanks for all the advice. i'll test it.
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Dakota Jack [mailto:[hidden email]]
> > > Gesendet: Freitag, 6. Mai 2005 09:55
> > > An: Jakarta Commons Users List
> > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > >
> > > I tested it out on both file separators (linux and microsoft)
> > > and it works on both.  Just run a test and see if it works.  It does
> > >
> > >
> > > public class Test {
> > >   public static void main(String [] params) {
> > >     File ie = new File("C:\\mydir\\myfile.txt");
> > >     File linux = new File("/mydir/myfile.txt");
> > >     StdOut.log("log.development","Test ttf ie.getName() = " +
> > > ie.getName());
> > >     StdOut.log("log.development","Test ttf linux.getName() =
> > > " + linux.getName()); }
> > >
> > > You should just use System.out.println() of course.
> > >
> > >
> > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > i can not figure out how this should work. this is a web
> > > application. linux and windows clients are accessing the app.
> > > the filename can be /mydir/myfile.txt and
> > > C:\mydir\myfile.txt. how should the server know which file
> > > separator to use. hmm. i could take a look at the http
> > > request data. ain't there a field for the operating system.
> > > but that ain't something i like to do. these things are
> > > always changing.
> > > >
> > > > i'll try your code later. thanks.
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > > > An: Jakarta Commons Users List
> > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > >
> > > > > This code should definitely work.  If it does not, I sure
> > > would like
> > > > > to know what happens.  What did happen?  Did you debug it?
> > > > >
> > > > >
> > > > >
> > > > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > > >
> > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > > > >
> > > > > > > Just so there is no misunderstanding, the browsers have
> > > > > nothing to
> > > > > > > do with what getName returns.  The browsers differ in
> > > > > what name they
> > > > > > > provide for the file.  Thus, when you get a File
> > > object for IE
> > > > > > > it gives the full name and for the others the actual file
> > > > > name itself.
> > > > > > thanks for the extra explanation. it's what i understood in
> > > > > the first place (no offense on this one).
> > > > > >
> > > > > >
> > > > > > > You make them all the same if you change
> > > commonsupload to give
> > > > > > > you
> > > > > > > file,getName() rather than just file.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >     // Just add this to the "protected String getFileName(Map
> > > > > > > headers)" method in FileUploadBase
> > > > > > >     if(fileName != null) {
> > > > > > >       fileName = new java.io.File(fileName).getName();
> > > > > > >     }
> > > > > >
> > > > > > tried that in the first place in my programm. but as the
> > > > > filename is something like C:\mydir\myfile.txt (windows file
> > > > > path) it doesn't seem to work on the linux server i'm
> > > running. file
> > > > > separators are different. correct me if i'm wrong.
> > > > > >
> > > > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > > > server. on linux the file separator is a slash ( / ) and not a
> > > > > backslash ( \ ). so my linux server searches for a slash
> > > in the full
> > > > > filename to get just the filename. but there is none. so
> > > it assumes
> > > > > it is the filename and returns it all.
> > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > > > thanks to all the responses for my question.
> > > > > > > >
> > > > > > > > actually i didn't know that it was a browser "thing". i
> > > > > > > thought it was
> > > > > > > > an operating system thing. thanks for clearing this up. and
> > > > > > > as this is
> > > > > > > > a browser specific thing IMHO there should be just a
> > > > > change in the
> > > > > > > > docu where you should add the fact that the IE is
> > > not behaving
> > > > > > > > like any other browser with the method getName.
> > > that would be
> > > > > > > > of
> > > > > > > much help.
> > > > > > > >
> > > > > > > > and this is the kind of "feature" i don't like of
> > > MS software.
> > > > > > > >
> > > > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > > > I know, I've run into this myself... But, it should
> > > > > be a fairly
> > > > > > > > > trivial exercise to write code to extract just the
> > > > > filename (as
> > > > > > > > > I believe you've done).  This makes sense to me as an
> > > > > additional
> > > > > > > > > method.  That way no existing code gets broken, but newer
> > > > > > > code can
> > > > > > > > > use the new method, which works as getName()
> > > probably should
> > > > > > > > > have been working all along anyway (IMHO).
> > > > > > > > >
> > > > > > > > > Frank
> > > > > > > > >
> > > > > > > > > Dakota Jack wrote:
> > > > > > > > > > The data difference is not in the code but in the
> > > > > request data
> > > > > > > > > > from the browser.  IE puts in the full name and other
> > > > > > > browsers put
> > > > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > > > same result
> > > > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > > > full name
> > > > > > > > > > from the browsers that send only the file name.
> > > > > There is no
> > > > > > > > > > reason, of course, to know the full name.
> > > > > > > > > >
> > > > > > > > > > On 5/4/05, Frank W. Zammetti
> > > <[hidden email]> wrote:
> > > > > > > > > >
> > > > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > > > a lot of sense...
> > > > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > > > to what's
> > > > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > > > >>getName() returned just the name while there
> > > was another
> > > > > > > > > >>method, maybe
> > > > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > > > but that
> > > > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > > > see why that
> > > > > > > > > >>hasn't been done, but adding something like
> > > > > getJustTheName()
> > > > > > > > > >>or something (obviously there must be a better choice!)
> > > > > > > makes sense to me.
> > > > > > > > > >>
> > > > > > > > > >>Frank
> > > > > > > > > >>
> > > > > > > > > >>Dakota Jack wrote:
> > > > > > > > > >>
> > > > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > > > how horrible
> > > > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > > > where there
> > > > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > > > at changing
> > > > > > > > > >>>code, even with the Java distribution itself, license
> > > > > > > issues notwithstanding.
> > > > > > > > > >>>
> > > > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > > > >>><[hidden email]>
> > > > > > > > wrote:
> > > > > > > > > >>>
> > > > > > > > > >>>
> > > > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > > > >>>>
> > > > > > > > > >>>>
> > > > > > > > > >>>>>Some people think this is a bug and some people
> > > > > > > think that this
> > > > > > > > > >>>>>is a feature.
> > > > > > > > > >>>>
> > > > > > > > > >>>><snip>
> > > > > > > > > >>>>
> > > > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > > > changed the
> > > > > > > > > >>>>>commons upload code adding .getName() to the
> > > > > file at this
> > > > > > > > > >>>>>stage.  The problem you are seeing is in
> > > > > Internet Explorer,
> > > > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > > > and Internet
> > > > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > > > either have to
> > > > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > > > where it
> > > > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > > > mechanisms after
> > > > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > > > somewhere, so I
> > > > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > > > "feature".
> > > > > > > > > >>>>
> > > > > > > > > >>>>the great thing about open source is that you are
> > > > > free to do
> > > > > > > > > >>>>exactly this :)
> > > > > > > > > >>>>
> > > > > > > > > >>>>- robert
> > > > > > > >
> > > > > >
> > > > > >
> > > > >
> > > --------------------------------------------------------------------
> > > > > -
> > > > > > To unsubscribe, e-mail:
> > > > > > [hidden email]
> > > > > > For additional commands, e-mail:
> > > > > [hidden email]
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > "You can lead a horse to water but you cannot make it
> > > float on its
> > > > > back."
> > > > > ~Dakota Jack~
> > > > >
> > > > >
> > > --------------------------------------------------------------------
> > > > > - To unsubscribe, e-mail:
> > > > > [hidden email]
> > > > > For additional commands, e-mail:
> > > > > [hidden email]
> > > > >
> > > > >
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail:
> > > [hidden email]
> > > >
> > > >
> > >
> > >
> > > --
> > > "You can lead a horse to water but you cannot make it float
> > > on its back."
> > > ~Dakota Jack~
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Knezevic, Mihael
In reply to this post by Dakota Jack
got some time for the testing now.

my test env:
Debian GNU/Linux 3.0 Sarge
Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)

my code:
System.out.println("-------- Test ----------");
System.out.println("Windows file name: " + new
File("C\\Windows\\Temp\\myfile.txt").getName());
System.out.println("Linux file name: " + new
File("/tmp/myfile.txt").getName());
System.out.println("-------- End  ----------");

my output:
-------- Test ----------
Windows file name: C:\Windows\Temp\myfile.txt
Linux file name: myfile.txt
-------- End  ----------

and it is as i expected. it takes the local file separator which is not in the
windows file name. so it returns the absolute file name IMO.

Am Freitag, 6. Mai 2005 09:54 schrieb Dakota Jack:

> I tested it out on both file separators (linux and microsoft) and it
> works on both.  Just run a test and see if it works.  It does
>
>
> public class Test {
>   public static void main(String [] params) {
>     File ie = new File("C:\\mydir\\myfile.txt");
>     File linux = new File("/mydir/myfile.txt");
>     StdOut.log("log.development","Test ttf ie.getName() = " + ie.getName());
>     StdOut.log("log.development","Test ttf linux.getName() = " +
> linux.getName());
> }
>
> You should just use System.out.println() of course.
>
>
> On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > i can not figure out how this should work. this is a web application.
linux and windows clients are accessing the app. the filename can
be /mydir/myfile.txt and C:\mydir\myfile.txt. how should the server know
which file separator to use. hmm. i could take a look at the http request
data. ain't there a field for the operating system. but that ain't something
i like to do. these things are always changing.

> >
> > i'll try your code later. thanks.
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Dakota Jack [mailto:[hidden email]]
> > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > An: Jakarta Commons Users List
> > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > >
> > > This code should definitely work.  If it does not, I sure
> > > would like to know what happens.  What did happen?  Did you debug it?
> > >
> > >
> > >
> > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > >
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > >
> > > > > Just so there is no misunderstanding, the browsers have
> > > nothing to
> > > > > do with what getName returns.  The browsers differ in
> > > what name they
> > > > > provide for the file.  Thus, when you get a File object for IE it
> > > > > gives the full name and for the others the actual file
> > > name itself.
> > > > thanks for the extra explanation. it's what i understood in
> > > the first place (no offense on this one).
> > > >
> > > >
> > > > > You make them all the same if you change commonsupload to give you
> > > > > file,getName() rather than just file.
> > > > >
> > > > >
> > > > >
> > > > >     // Just add this to the "protected String getFileName(Map
> > > > > headers)" method in FileUploadBase
> > > > >     if(fileName != null) {
> > > > >       fileName = new java.io.File(fileName).getName();
> > > > >     }
> > > >
> > > > tried that in the first place in my programm. but as the
> > > filename is something like C:\mydir\myfile.txt (windows file
> > > path) it doesn't seem to work on the linux server i'm
> > > running. file separators are different. correct me if i'm wrong.
> > > >
> > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > server. on linux the file separator is a slash ( / ) and not
> > > a backslash ( \ ). so my linux server searches for a slash in
> > > the full filename to get just the filename. but there is
> > > none. so it assumes it is the filename and returns it all.
> > > >
> > > > >
> > > > >
> > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > thanks to all the responses for my question.
> > > > > >
> > > > > > actually i didn't know that it was a browser "thing". i
> > > > > thought it was
> > > > > > an operating system thing. thanks for clearing this up. and
> > > > > as this is
> > > > > > a browser specific thing IMHO there should be just a
> > > change in the
> > > > > > docu where you should add the fact that the IE is not behaving
> > > > > > like any other browser with the method getName. that would be of
> > > > > much help.
> > > > > >
> > > > > > and this is the kind of "feature" i don't like of MS software.
> > > > > >
> > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > I know, I've run into this myself... But, it should
> > > be a fairly
> > > > > > > trivial exercise to write code to extract just the
> > > filename (as
> > > > > > > I believe you've done).  This makes sense to me as an
> > > additional
> > > > > > > method.  That way no existing code gets broken, but newer
> > > > > code can
> > > > > > > use the new method, which works as getName() probably should
> > > > > > > have been working all along anyway (IMHO).
> > > > > > >
> > > > > > > Frank
> > > > > > >
> > > > > > > Dakota Jack wrote:
> > > > > > > > The data difference is not in the code but in the
> > > request data
> > > > > > > > from the browser.  IE puts in the full name and other
> > > > > browsers put
> > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > same result
> > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > full name
> > > > > > > > from the browsers that send only the file name.
> > > There is no
> > > > > > > > reason, of course, to know the full name.
> > > > > > > >
> > > > > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > > > > >
> > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > a lot of sense...
> > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > to what's
> > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > >>getName() returned just the name while there was another
> > > > > > > >>method, maybe
> > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > but that
> > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > see why that
> > > > > > > >>hasn't been done, but adding something like
> > > getJustTheName()
> > > > > > > >>or something (obviously there must be a better choice!)
> > > > > makes sense to me.
> > > > > > > >>
> > > > > > > >>Frank
> > > > > > > >>
> > > > > > > >>Dakota Jack wrote:
> > > > > > > >>
> > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > how horrible
> > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > where there
> > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > at changing
> > > > > > > >>>code, even with the Java distribution itself, license
> > > > > issues notwithstanding.
> > > > > > > >>>
> > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > >>><[hidden email]>
> > > > > > wrote:
> > > > > > > >>>
> > > > > > > >>>
> > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > >>>>
> > > > > > > >>>>
> > > > > > > >>>>>Some people think this is a bug and some people
> > > > > think that this
> > > > > > > >>>>>is a feature.
> > > > > > > >>>>
> > > > > > > >>>><snip>
> > > > > > > >>>>
> > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > changed the
> > > > > > > >>>>>commons upload code adding .getName() to the
> > > file at this
> > > > > > > >>>>>stage.  The problem you are seeing is in
> > > Internet Explorer,
> > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > and Internet
> > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > either have to
> > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > where it
> > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > mechanisms after
> > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > somewhere, so I
> > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > "feature".
> > > > > > > >>>>
> > > > > > > >>>>the great thing about open source is that you are
> > > free to do
> > > > > > > >>>>exactly this :)
> > > > > > > >>>>
> > > > > > > >>>>- robert
> > > > > >
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail:
> > > [hidden email]
> > > >
> > > >
> > >
> > >
> > > --
> > > "You can lead a horse to water but you cannot make it float
> > > on its back."
> > > ~Dakota Jack~
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
Hmmmm?  That is very odd.  I ran the same code and got:

Windows file name: myfile.txt
Linux file name: myfile.txt
-------- End  ----------

However, your name of the Windows file is not correct, i.e. not really
a Windows file name.  You might try correcting for that.  I think the
real name is something like \\C:\\\\ blah, blah, but you definitely
have to put in the colon.  Why don't you do this, try changing the
code in the actual FileUploadBase and see what your results are.
Also, you might see what you are getting as the file name from a
Windows machine browser.,  Sound like a plan?  I am really surprised
at your result, because the Sun Java code clearly is supposed to
normalize any file name which should account for any differences in
the slashes.  There is no other point in normalizing, after all.  The
actual code in File is:


    public File(String pathname) {
        if (pathname == null) {
            throw new NullPointerException();
        }
        this.path = fs.normalize(pathname);
        this.prefixLength = fs.prefixLength(this.path);
    }

and

    public String getName() {
        int index = path.lastIndexOf(separatorChar);
        if (index < prefixLength) return path.substring(prefixLength);
        return path.substring(index + 1);
    }

As a result, when you are creating the File object your String is not
being normalized with separatorChar's.  That leads me to think that
the problems with the way you specify the file path, e.g. no colon,
are causing the problem with your JVM.

Let me know.  This is curious.  

Anyone else have an idea?

The bottom line is to test the code with FileUploadBase.  Mine has
been working well in production as is for some time.  I have not
tested it, however, from a Linux browser.


On 5/6/05, Mihael Knezevic <[hidden email]> wrote:

> got some time for the testing now.
>
> my test env:
> Debian GNU/Linux 3.0 Sarge
> Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
>
> my code:
> System.out.println("-------- Test ----------");
> System.out.println("Windows file name: " + new
> File("C\\Windows\\Temp\\myfile.txt").getName());
> System.out.println("Linux file name: " + new
> File("/tmp/myfile.txt").getName());
> System.out.println("-------- End  ----------");
>
> my output:
> -------- Test ----------
> Windows file name: C:\Windows\Temp\myfile.txt
> Linux file name: myfile.txt
> -------- End  ----------
>
> and it is as i expected. it takes the local file separator which is not in the
> windows file name. so it returns the absolute file name IMO.
>
> Am Freitag, 6. Mai 2005 09:54 schrieb Dakota Jack:
> > I tested it out on both file separators (linux and microsoft) and it
> > works on both.  Just run a test and see if it works.  It does
> >
> >
> > public class Test {
> >   public static void main(String [] params) {
> >     File ie = new File("C:\\mydir\\myfile.txt");
> >     File linux = new File("/mydir/myfile.txt");
> >     StdOut.log("log.development","Test ttf ie.getName() = " + ie.getName());
> >     StdOut.log("log.development","Test ttf linux.getName() = " +
> > linux.getName());
> > }
> >
> > You should just use System.out.println() of course.
> >
> >
> > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > i can not figure out how this should work. this is a web application.
> linux and windows clients are accessing the app. the filename can
> be /mydir/myfile.txt and C:\mydir\myfile.txt. how should the server know
> which file separator to use. hmm. i could take a look at the http request
> data. ain't there a field for the operating system. but that ain't something
> i like to do. these things are always changing.
> > >
> > > i'll try your code later. thanks.
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > > An: Jakarta Commons Users List
> > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > >
> > > > This code should definitely work.  If it does not, I sure
> > > > would like to know what happens.  What did happen?  Did you debug it?
> > > >
> > > >
> > > >
> > > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > >
> > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > > >
> > > > > > Just so there is no misunderstanding, the browsers have
> > > > nothing to
> > > > > > do with what getName returns.  The browsers differ in
> > > > what name they
> > > > > > provide for the file.  Thus, when you get a File object for IE it
> > > > > > gives the full name and for the others the actual file
> > > > name itself.
> > > > > thanks for the extra explanation. it's what i understood in
> > > > the first place (no offense on this one).
> > > > >
> > > > >
> > > > > > You make them all the same if you change commonsupload to give you
> > > > > > file,getName() rather than just file.
> > > > > >
> > > > > >
> > > > > >
> > > > > >     // Just add this to the "protected String getFileName(Map
> > > > > > headers)" method in FileUploadBase
> > > > > >     if(fileName != null) {
> > > > > >       fileName = new java.io.File(fileName).getName();
> > > > > >     }
> > > > >
> > > > > tried that in the first place in my programm. but as the
> > > > filename is something like C:\mydir\myfile.txt (windows file
> > > > path) it doesn't seem to work on the linux server i'm
> > > > running. file separators are different. correct me if i'm wrong.
> > > > >
> > > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > > server. on linux the file separator is a slash ( / ) and not
> > > > a backslash ( \ ). so my linux server searches for a slash in
> > > > the full filename to get just the filename. but there is
> > > > none. so it assumes it is the filename and returns it all.
> > > > >
> > > > > >
> > > > > >
> > > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > > thanks to all the responses for my question.
> > > > > > >
> > > > > > > actually i didn't know that it was a browser "thing". i
> > > > > > thought it was
> > > > > > > an operating system thing. thanks for clearing this up. and
> > > > > > as this is
> > > > > > > a browser specific thing IMHO there should be just a
> > > > change in the
> > > > > > > docu where you should add the fact that the IE is not behaving
> > > > > > > like any other browser with the method getName. that would be of
> > > > > > much help.
> > > > > > >
> > > > > > > and this is the kind of "feature" i don't like of MS software.
> > > > > > >
> > > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > > I know, I've run into this myself... But, it should
> > > > be a fairly
> > > > > > > > trivial exercise to write code to extract just the
> > > > filename (as
> > > > > > > > I believe you've done).  This makes sense to me as an
> > > > additional
> > > > > > > > method.  That way no existing code gets broken, but newer
> > > > > > code can
> > > > > > > > use the new method, which works as getName() probably should
> > > > > > > > have been working all along anyway (IMHO).
> > > > > > > >
> > > > > > > > Frank
> > > > > > > >
> > > > > > > > Dakota Jack wrote:
> > > > > > > > > The data difference is not in the code but in the
> > > > request data
> > > > > > > > > from the browser.  IE puts in the full name and other
> > > > > > browsers put
> > > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > > same result
> > > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > > full name
> > > > > > > > > from the browsers that send only the file name.
> > > > There is no
> > > > > > > > > reason, of course, to know the full name.
> > > > > > > > >
> > > > > > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > > > > > >
> > > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > > a lot of sense...
> > > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > > to what's
> > > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > > >>getName() returned just the name while there was another
> > > > > > > > >>method, maybe
> > > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > > but that
> > > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > > see why that
> > > > > > > > >>hasn't been done, but adding something like
> > > > getJustTheName()
> > > > > > > > >>or something (obviously there must be a better choice!)
> > > > > > makes sense to me.
> > > > > > > > >>
> > > > > > > > >>Frank
> > > > > > > > >>
> > > > > > > > >>Dakota Jack wrote:
> > > > > > > > >>
> > > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > > how horrible
> > > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > > where there
> > > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > > at changing
> > > > > > > > >>>code, even with the Java distribution itself, license
> > > > > > issues notwithstanding.
> > > > > > > > >>>
> > > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > > >>><[hidden email]>
> > > > > > > wrote:
> > > > > > > > >>>
> > > > > > > > >>>
> > > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>>Some people think this is a bug and some people
> > > > > > think that this
> > > > > > > > >>>>>is a feature.
> > > > > > > > >>>>
> > > > > > > > >>>><snip>
> > > > > > > > >>>>
> > > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > > changed the
> > > > > > > > >>>>>commons upload code adding .getName() to the
> > > > file at this
> > > > > > > > >>>>>stage.  The problem you are seeing is in
> > > > Internet Explorer,
> > > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > > and Internet
> > > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > > either have to
> > > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > > where it
> > > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > > mechanisms after
> > > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > > somewhere, so I
> > > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > > "feature".
> > > > > > > > >>>>
> > > > > > > > >>>>the great thing about open source is that you are
> > > > free to do
> > > > > > > > >>>>exactly this :)
> > > > > > > > >>>>
> > > > > > > > >>>>- robert
> > > > > > >
> > > > >
> > > > >
> > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [hidden email]
> > > > > For additional commands, e-mail:
> > > > [hidden email]
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > "You can lead a horse to water but you cannot make it float
> > > > on its back."
> > > > ~Dakota Jack~
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
In reply to this post by Knezevic, Mihael
The File class definitely does not "take the local file separator",
Mihael.  It normalizes the String, which does not include a file
separator at all.  Either the normalization is not working, which
would be very odd, or your errors in the file name are what is causing
the problem.  At least that is what I think.  My setup worked with
your code, however, so I don't know what is up.

Anyone have an idea on this?

On 5/6/05, Mihael Knezevic <[hidden email]> wrote:

> got some time for the testing now.
>
> my test env:
> Debian GNU/Linux 3.0 Sarge
> Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
>
> my code:
> System.out.println("-------- Test ----------");
> System.out.println("Windows file name: " + new
> File("C\\Windows\\Temp\\myfile.txt").getName());
> System.out.println("Linux file name: " + new
> File("/tmp/myfile.txt").getName());
> System.out.println("-------- End  ----------");
>
> my output:
> -------- Test ----------
> Windows file name: C:\Windows\Temp\myfile.txt
> Linux file name: myfile.txt
> -------- End  ----------
>
> and it is as i expected. it takes the local file separator which is not in the
> windows file name. so it returns the absolute file name IMO.
>
> Am Freitag, 6. Mai 2005 09:54 schrieb Dakota Jack:
> > I tested it out on both file separators (linux and microsoft) and it
> > works on both.  Just run a test and see if it works.  It does
> >
> >
> > public class Test {
> >   public static void main(String [] params) {
> >     File ie = new File("C:\\mydir\\myfile.txt");
> >     File linux = new File("/mydir/myfile.txt");
> >     StdOut.log("log.development","Test ttf ie.getName() = " + ie.getName());
> >     StdOut.log("log.development","Test ttf linux.getName() = " +
> > linux.getName());
> > }
> >
> > You should just use System.out.println() of course.
> >
> >
> > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > i can not figure out how this should work. this is a web application.
> linux and windows clients are accessing the app. the filename can
> be /mydir/myfile.txt and C:\mydir\myfile.txt. how should the server know
> which file separator to use. hmm. i could take a look at the http request
> data. ain't there a field for the operating system. but that ain't something
> i like to do. these things are always changing.
> > >
> > > i'll try your code later. thanks.
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > > An: Jakarta Commons Users List
> > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > >
> > > > This code should definitely work.  If it does not, I sure
> > > > would like to know what happens.  What did happen?  Did you debug it?
> > > >
> > > >
> > > >
> > > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > >
> > > > >
> > > > > > -----Ursprüngliche Nachricht-----
> > > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > > >
> > > > > > Just so there is no misunderstanding, the browsers have
> > > > nothing to
> > > > > > do with what getName returns.  The browsers differ in
> > > > what name they
> > > > > > provide for the file.  Thus, when you get a File object for IE it
> > > > > > gives the full name and for the others the actual file
> > > > name itself.
> > > > > thanks for the extra explanation. it's what i understood in
> > > > the first place (no offense on this one).
> > > > >
> > > > >
> > > > > > You make them all the same if you change commonsupload to give you
> > > > > > file,getName() rather than just file.
> > > > > >
> > > > > >
> > > > > >
> > > > > >     // Just add this to the "protected String getFileName(Map
> > > > > > headers)" method in FileUploadBase
> > > > > >     if(fileName != null) {
> > > > > >       fileName = new java.io.File(fileName).getName();
> > > > > >     }
> > > > >
> > > > > tried that in the first place in my programm. but as the
> > > > filename is something like C:\mydir\myfile.txt (windows file
> > > > path) it doesn't seem to work on the linux server i'm
> > > > running. file separators are different. correct me if i'm wrong.
> > > > >
> > > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > > server. on linux the file separator is a slash ( / ) and not
> > > > a backslash ( \ ). so my linux server searches for a slash in
> > > > the full filename to get just the filename. but there is
> > > > none. so it assumes it is the filename and returns it all.
> > > > >
> > > > > >
> > > > > >
> > > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > > thanks to all the responses for my question.
> > > > > > >
> > > > > > > actually i didn't know that it was a browser "thing". i
> > > > > > thought it was
> > > > > > > an operating system thing. thanks for clearing this up. and
> > > > > > as this is
> > > > > > > a browser specific thing IMHO there should be just a
> > > > change in the
> > > > > > > docu where you should add the fact that the IE is not behaving
> > > > > > > like any other browser with the method getName. that would be of
> > > > > > much help.
> > > > > > >
> > > > > > > and this is the kind of "feature" i don't like of MS software.
> > > > > > >
> > > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > > I know, I've run into this myself... But, it should
> > > > be a fairly
> > > > > > > > trivial exercise to write code to extract just the
> > > > filename (as
> > > > > > > > I believe you've done).  This makes sense to me as an
> > > > additional
> > > > > > > > method.  That way no existing code gets broken, but newer
> > > > > > code can
> > > > > > > > use the new method, which works as getName() probably should
> > > > > > > > have been working all along anyway (IMHO).
> > > > > > > >
> > > > > > > > Frank
> > > > > > > >
> > > > > > > > Dakota Jack wrote:
> > > > > > > > > The data difference is not in the code but in the
> > > > request data
> > > > > > > > > from the browser.  IE puts in the full name and other
> > > > > > browsers put
> > > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > > same result
> > > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > > full name
> > > > > > > > > from the browsers that send only the file name.
> > > > There is no
> > > > > > > > > reason, of course, to know the full name.
> > > > > > > > >
> > > > > > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > > > > > >
> > > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > > a lot of sense...
> > > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > > to what's
> > > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > > >>getName() returned just the name while there was another
> > > > > > > > >>method, maybe
> > > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > > but that
> > > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > > see why that
> > > > > > > > >>hasn't been done, but adding something like
> > > > getJustTheName()
> > > > > > > > >>or something (obviously there must be a better choice!)
> > > > > > makes sense to me.
> > > > > > > > >>
> > > > > > > > >>Frank
> > > > > > > > >>
> > > > > > > > >>Dakota Jack wrote:
> > > > > > > > >>
> > > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > > how horrible
> > > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > > where there
> > > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > > at changing
> > > > > > > > >>>code, even with the Java distribution itself, license
> > > > > > issues notwithstanding.
> > > > > > > > >>>
> > > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > > >>><[hidden email]>
> > > > > > > wrote:
> > > > > > > > >>>
> > > > > > > > >>>
> > > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > > >>>>
> > > > > > > > >>>>
> > > > > > > > >>>>>Some people think this is a bug and some people
> > > > > > think that this
> > > > > > > > >>>>>is a feature.
> > > > > > > > >>>>
> > > > > > > > >>>><snip>
> > > > > > > > >>>>
> > > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > > changed the
> > > > > > > > >>>>>commons upload code adding .getName() to the
> > > > file at this
> > > > > > > > >>>>>stage.  The problem you are seeing is in
> > > > Internet Explorer,
> > > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > > and Internet
> > > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > > either have to
> > > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > > where it
> > > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > > mechanisms after
> > > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > > somewhere, so I
> > > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > > "feature".
> > > > > > > > >>>>
> > > > > > > > >>>>the great thing about open source is that you are
> > > > free to do
> > > > > > > > >>>>exactly this :)
> > > > > > > > >>>>
> > > > > > > > >>>>- robert
> > > > > > >
> > > > >
> > > > >
> > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [hidden email]
> > > > > For additional commands, e-mail:
> > > > [hidden email]
> > > > >
> > > > >
> > > >
> > > >
> > > > --
> > > > "You can lead a horse to water but you cannot make it float
> > > > on its back."
> > > > ~Dakota Jack~
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> >
> > --
> > "You can lead a horse to water but you cannot make it float on its back."
> > ~Dakota Jack~
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [FileUpload] Getting wrong filename from FileItem

Dakota Jack
I have done a bit more testing, Mihael, with interesting results.  The
name of the file in the String is very important.  From

public class Test {
  public static void main(String [] params) throws Exception {
   
    System.out.println("-------- Test C\\Windows\\Temp\\myfile.txt ----------");
    System.out.println("Windows getName: " + new
File("C\\Windows\\Temp\\myfile.txt").getName());
    System.out.println("Windows getPath: " + new
File("C\\Windows\\Temp\\myfile.txt").getPath());
    System.out.println("Windows getAbsoluteFile: " + new
File("C\\Windows\\Temp\\myfile.txt").getAbsoluteFile());
    System.out.println("Windows getAbsolutePath: " + new
File("C\\Windows\\Temp\\myfile.txt").getAbsolutePath());
    System.out.println("Windows getCanonicalFile: " + new
File("C\\Windows\\Temp\\myfile.txt").getCanonicalFile());
    System.out.println("Windows getCanonicalPath: " + new
File("C\\Windows\\Temp\\myfile.txt").getCanonicalPath());
    System.out.println("-------- Test C:\\Windows\\Temp\\myfile.txt
----------");
    System.out.println("Windows getName: " + new
File("C:\\Windows\\Temp\\myfile.txt").getName());
    System.out.println("Windows getPath: " + new
File("C:\\Windows\\Temp\\myfile.txt").getPath());
    System.out.println("Windows getAbsoluteFile: " + new
File("C:\\Windows\\Temp\\myfile.txt").getAbsoluteFile());
    System.out.println("Windows getAbsolutePath: " + new
File("C:\\Windows\\Temp\\myfile.txt").getAbsolutePath());
    System.out.println("Windows getCanonicalFile: " + new
File("C:\\Windows\\Temp\\myfile.txt").getCanonicalFile());
    System.out.println("Windows getCanonicalPath: " + new
File("C:\\Windows\\Temp\\myfile.txt").getCanonicalPath());
    System.out.println("-------- Test \\C:\\Windows\\Temp\\myfile.txt
----------");
    System.out.println("Windows getName: " + new
File("\\C:\\Windows\\Temp\\myfile.txt").getName());
    System.out.println("Windows getPath: " + new
File("\\C:\\Windows\\Temp\\myfile.txt").getPath());
    System.out.println("Windows getAbsoluteFile: " + new
File("\\C:\\Windows\\Temp\\myfile.txt").getAbsoluteFile());
    System.out.println("Windows getAbsolutePath: " + new
File("\\C:\\Windows\\Temp\\myfile.txt").getAbsolutePath());
    System.out.println("Windows getCanonicalFile: " + new
File("\\C:\\Windows\\Temp\\myfile.txt").getCanonicalFile());
    System.out.println("Windows getCanonicalPath: " + new
File("\\C:\\Windows\\Temp\\myfile.txt").getCanonicalPath());
    System.out.println("Linux getName: " + new
File("/tmp/myfile.txt").getName());
    System.out.println("Linux getPath: " + new
File("/tmp/myfile.txt").getPath());
    System.out.println("Linux getAbsoluteFile: " + new
File("/tmp/myfile.txt").getAbsoluteFile());
    System.out.println("Linux getAbsolutePath: " + new
File("/tmp/myfile.txt").getAbsolutePath());
    System.out.println("Linux getCanonicalFile: " + new
File("/tmp/myfile.txt").getCanonicalFile());
    System.out.println("Linux getCanonicalPath: " + new
File("/tmp/myfile.txt").getCanonicalPath());
    System.out.println("-------- End  ----------");

    System.exit(0);
  }
}


I got these results:

-------- Test C\Windows\Temp\myfile.txt ----------
Windows getName: myfile.txt
Windows getPath: C\Windows\Temp\myfile.txt
Windows getAbsoluteFile:
C:\crackwillow\webapps\ROOT\WEB-INF\classes\com\crackwillow\testing\C\Windows\Temp\myfile.txt
Windows getAbsolutePath:
C:\crackwillow\webapps\ROOT\WEB-INF\classes\com\crackwillow\testing\C\Windows\Temp\myfile.txt
Windows getCanonicalFile:
C:\crackwillow\webapps\ROOT\WEB-INF\classes\com\crackwillow\testing\C\Windows\Temp\myfile.txt
Windows getCanonicalPath:
C:\crackwillow\webapps\ROOT\WEB-INF\classes\com\crackwillow\testing\C\Windows\Temp\myfile.txt
-------- Test C:\Windows\Temp\myfile.txt ----------
Windows getName: myfile.txt
Windows getPath: C:\Windows\Temp\myfile.txt
Windows getAbsoluteFile: C:\Windows\Temp\myfile.txt
Windows getAbsolutePath: C:\Windows\Temp\myfile.txt
Windows getCanonicalFile: C:\WINDOWS\Temp\myfile.txt
Windows getCanonicalPath: C:\WINDOWS\Temp\myfile.txt
-------- Test \C:\Windows\Temp\myfile.txt ----------
Windows getName: myfile.txt
Windows getPath: C:\Windows\Temp\myfile.txt
Windows getAbsoluteFile: C:\Windows\Temp\myfile.txt
Windows getAbsolutePath: C:\Windows\Temp\myfile.txt
Windows getCanonicalFile: C:\WINDOWS\Temp\myfile.txt
Windows getCanonicalPath: C:\WINDOWS\Temp\myfile.txt
Linux getName: myfile.txt
Linux getPath: \tmp\myfile.txt
Linux getAbsoluteFile: C:\tmp\myfile.txt
Linux getAbsolutePath: C:\tmp\myfile.txt
Linux getCanonicalFile: C:\tmp\myfile.txt
Linux getCanonicalPath: C:\tmp\myfile.txt
-------- End  ----------


On 5/6/05, Dakota Jack <[hidden email]> wrote:

> The File class definitely does not "take the local file separator",
> Mihael.  It normalizes the String, which does not include a file
> separator at all.  Either the normalization is not working, which
> would be very odd, or your errors in the file name are what is causing
> the problem.  At least that is what I think.  My setup worked with
> your code, however, so I don't know what is up.
>
> Anyone have an idea on this?
>
> On 5/6/05, Mihael Knezevic <[hidden email]> wrote:
> > got some time for the testing now.
> >
> > my test env:
> > Debian GNU/Linux 3.0 Sarge
> > Java HotSpot(TM) Client VM (build 1.4.2_06-b03, mixed mode)
> >
> > my code:
> > System.out.println("-------- Test ----------");
> > System.out.println("Windows file name: " + new
> > File("C\\Windows\\Temp\\myfile.txt").getName());
> > System.out.println("Linux file name: " + new
> > File("/tmp/myfile.txt").getName());
> > System.out.println("-------- End  ----------");
> >
> > my output:
> > -------- Test ----------
> > Windows file name: C:\Windows\Temp\myfile.txt
> > Linux file name: myfile.txt
> > -------- End  ----------
> >
> > and it is as i expected. it takes the local file separator which is not in the
> > windows file name. so it returns the absolute file name IMO.
> >
> > Am Freitag, 6. Mai 2005 09:54 schrieb Dakota Jack:
> > > I tested it out on both file separators (linux and microsoft) and it
> > > works on both.  Just run a test and see if it works.  It does
> > >
> > >
> > > public class Test {
> > >   public static void main(String [] params) {
> > >     File ie = new File("C:\\mydir\\myfile.txt");
> > >     File linux = new File("/mydir/myfile.txt");
> > >     StdOut.log("log.development","Test ttf ie.getName() = " + ie.getName());
> > >     StdOut.log("log.development","Test ttf linux.getName() = " +
> > > linux.getName());
> > > }
> > >
> > > You should just use System.out.println() of course.
> > >
> > >
> > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > i can not figure out how this should work. this is a web application.
> > linux and windows clients are accessing the app. the filename can
> > be /mydir/myfile.txt and C:\mydir\myfile.txt. how should the server know
> > which file separator to use. hmm. i could take a look at the http request
> > data. ain't there a field for the operating system. but that ain't something
> > i like to do. these things are always changing.
> > > >
> > > > i'll try your code later. thanks.
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > Gesendet: Freitag, 6. Mai 2005 09:34
> > > > > An: Jakarta Commons Users List
> > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > >
> > > > > This code should definitely work.  If it does not, I sure
> > > > > would like to know what happens.  What did happen?  Did you debug it?
> > > > >
> > > > >
> > > > >
> > > > > On 5/6/05, Knezevic, Mihael <[hidden email]> wrote:
> > > > > >
> > > > > >
> > > > > > > -----Ursprüngliche Nachricht-----
> > > > > > > Von: Dakota Jack [mailto:[hidden email]]
> > > > > > > Gesendet: Freitag, 6. Mai 2005 08:51
> > > > > > > An: Jakarta Commons Users List; Knezevic, Mihael
> > > > > > > Betreff: Re: [FileUpload] Getting wrong filename from FileItem
> > > > > > >
> > > > > > > Just so there is no misunderstanding, the browsers have
> > > > > nothing to
> > > > > > > do with what getName returns.  The browsers differ in
> > > > > what name they
> > > > > > > provide for the file.  Thus, when you get a File object for IE it
> > > > > > > gives the full name and for the others the actual file
> > > > > name itself.
> > > > > > thanks for the extra explanation. it's what i understood in
> > > > > the first place (no offense on this one).
> > > > > >
> > > > > >
> > > > > > > You make them all the same if you change commonsupload to give you
> > > > > > > file,getName() rather than just file.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > >     // Just add this to the "protected String getFileName(Map
> > > > > > > headers)" method in FileUploadBase
> > > > > > >     if(fileName != null) {
> > > > > > >       fileName = new java.io.File(fileName).getName();
> > > > > > >     }
> > > > > >
> > > > > > tried that in the first place in my programm. but as the
> > > > > filename is something like C:\mydir\myfile.txt (windows file
> > > > > path) it doesn't seem to work on the linux server i'm
> > > > > running. file separators are different. correct me if i'm wrong.
> > > > > >
> > > > > > windows client (ie) returns C:\mydir\myfile.txt to my linux
> > > > > server. on linux the file separator is a slash ( / ) and not
> > > > > a backslash ( \ ). so my linux server searches for a slash in
> > > > > the full filename to get just the filename. but there is
> > > > > none. so it assumes it is the filename and returns it all.
> > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On 5/5/05, Mihael Knezevic <[hidden email]> wrote:
> > > > > > > > thanks to all the responses for my question.
> > > > > > > >
> > > > > > > > actually i didn't know that it was a browser "thing". i
> > > > > > > thought it was
> > > > > > > > an operating system thing. thanks for clearing this up. and
> > > > > > > as this is
> > > > > > > > a browser specific thing IMHO there should be just a
> > > > > change in the
> > > > > > > > docu where you should add the fact that the IE is not behaving
> > > > > > > > like any other browser with the method getName. that would be of
> > > > > > > much help.
> > > > > > > >
> > > > > > > > and this is the kind of "feature" i don't like of MS software.
> > > > > > > >
> > > > > > > > Am Mittwoch, 4. Mai 2005 22:02 schrieb Frank W. Zammetti:
> > > > > > > > > I know, I've run into this myself... But, it should
> > > > > be a fairly
> > > > > > > > > trivial exercise to write code to extract just the
> > > > > filename (as
> > > > > > > > > I believe you've done).  This makes sense to me as an
> > > > > additional
> > > > > > > > > method.  That way no existing code gets broken, but newer
> > > > > > > code can
> > > > > > > > > use the new method, which works as getName() probably should
> > > > > > > > > have been working all along anyway (IMHO).
> > > > > > > > >
> > > > > > > > > Frank
> > > > > > > > >
> > > > > > > > > Dakota Jack wrote:
> > > > > > > > > > The data difference is not in the code but in the
> > > > > request data
> > > > > > > > > > from the browser.  IE puts in the full name and other
> > > > > > > browsers put
> > > > > > > > > > in just the name.  Calling [file].getName() gives the
> > > > > > > same result
> > > > > > > > > > for all of them.  I don't think there is a way to get a
> > > > > > > full name
> > > > > > > > > > from the browsers that send only the file name.
> > > > > There is no
> > > > > > > > > > reason, of course, to know the full name.
> > > > > > > > > >
> > > > > > > > > > On 5/4/05, Frank W. Zammetti <[hidden email]> wrote:
> > > > > > > > > >
> > > > > > > > > >>It seems to me a method to get JUST the filename makes
> > > > > > > a lot of sense...
> > > > > > > > > >>what has been the reason for not adding it IN ADDITION
> > > > > > > to what's
> > > > > > > > > >>there now?  Unfortunately it would make more sense if
> > > > > > > > > >>getName() returned just the name while there was another
> > > > > > > > > >>method, maybe
> > > > > > > > > >>getFullName() that returned what getName() returns now,
> > > > > > > but that
> > > > > > > > > >>breaks existing code potentially, so I can certainly
> > > > > > > see why that
> > > > > > > > > >>hasn't been done, but adding something like
> > > > > getJustTheName()
> > > > > > > > > >>or something (obviously there must be a better choice!)
> > > > > > > makes sense to me.
> > > > > > > > > >>
> > > > > > > > > >>Frank
> > > > > > > > > >>
> > > > > > > > > >>Dakota Jack wrote:
> > > > > > > > > >>
> > > > > > > > > >>>That is an excellent point, Robert.  I often forget
> > > > > > > how horrible
> > > > > > > > > >>>it must be to be immeshed in those programming worlds
> > > > > > > where there
> > > > > > > > > >>>is no recourse.  Too often we shy away, I think,
> > > > > at changing
> > > > > > > > > >>>code, even with the Java distribution itself, license
> > > > > > > issues notwithstanding.
> > > > > > > > > >>>
> > > > > > > > > >>>On 5/4/05, robert burrell donkin
> > > > > > > > > >>><[hidden email]>
> > > > > > > > wrote:
> > > > > > > > > >>>
> > > > > > > > > >>>
> > > > > > > > > >>>>On Wed, 2005-05-04 at 10:26 -0700, Dakota Jack wrote:
> > > > > > > > > >>>>
> > > > > > > > > >>>>
> > > > > > > > > >>>>>Some people think this is a bug and some people
> > > > > > > think that this
> > > > > > > > > >>>>>is a feature.
> > > > > > > > > >>>>
> > > > > > > > > >>>><snip>
> > > > > > > > > >>>>
> > > > > > > > > >>>>>That is not a problem, however.  I just went in and
> > > > > > > changed the
> > > > > > > > > >>>>>commons upload code adding .getName() to the
> > > > > file at this
> > > > > > > > > >>>>>stage.  The problem you are seeing is in
> > > > > Internet Explorer,
> > > > > > > > > >>>>>right?  Firefox and Netscape return the file name
> > > > > > > and Internet
> > > > > > > > > >>>>>Explorer returns the full path.  Anyway, you
> > > > > either have to
> > > > > > > > > >>>>>solve the problem in the commons upload code itself,
> > > > > > > where it
> > > > > > > > > >>>>>is easy to solve, or to go through some wasted
> > > > > > > mechanisms after
> > > > > > > > > >>>>>the fact.  Everyone has to solve this problem
> > > > > > > somewhere, so I
> > > > > > > > > >>>>>definitely come down on the side of "bug" versus
> > > > > "feature".
> > > > > > > > > >>>>
> > > > > > > > > >>>>the great thing about open source is that you are
> > > > > free to do
> > > > > > > > > >>>>exactly this :)
> > > > > > > > > >>>>
> > > > > > > > > >>>>- robert
> > > > > > > >
> > > > > >
> > > > > >
> > > > > ---------------------------------------------------------------------
> > > > > > To unsubscribe, e-mail: [hidden email]
> > > > > > For additional commands, e-mail:
> > > > > [hidden email]
> > > > > >
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > "You can lead a horse to water but you cannot make it float
> > > > > on its back."
> > > > > ~Dakota Jack~
> > > > >
> > > > > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: [hidden email]
> > > > > For additional commands, e-mail: [hidden email]
> > > > >
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> > >
> > > --
> > > "You can lead a horse to water but you cannot make it float on its back."
> > > ~Dakota Jack~
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> --
> "You can lead a horse to water but you cannot make it float on its back."
> ~Dakota Jack~
>


--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]