GWT : fileUpload.getFileName() & fakepath

拥有回忆 提交于 2020-01-02 05:13:12

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/6422103/gwt-fileupload-getfilename-fakepath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!