简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM