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 :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With