开发者

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.开发者_Go百科

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜