Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT : fileUpload.getFileName() & fakepath

I am working on a GWT project (web application) :

at some point, users can upload a file through the application via a FormPanel.

As I need the filename, I thought I could use :

    FileUpload upload = new FileUpload();
    // ...
    String name = upload.getFileName();

And name turns out to be something like this : C:\fakepath\whatever.txt.

Is this cross-platform ? What happens on other OS (I am using Windows) ?

like image 445
l0r3nz4cc10 Avatar asked Jun 21 '11 07:06

l0r3nz4cc10


1 Answers

The name returned by a upload form is dependent on the browser's security settings.

On windows, the C:\fakepath is used to obscure where the file is actually located. The filename, however, is always kept.

The same can happen on other os'es, it wouldn't be C:\fakepath (not 100% sure anymore what linux could return, for example).

I'm currently working on a GWT-based system too, using the FileUpload; and the filename hasn't been wrong on any of the used client os'es (only different (fake)paths). This was used on Windows, Ubuntu and OS/x. You should be able to safely get the correct filename by separating on the last "/" or "\" (do note that those differ per OS), or use the getFileName method for that :).

like image 52
Yhn Avatar answered Nov 10 '22 12:11

Yhn