-2

i'm beginner with GXT and i'm wondering if there is a way to parse a file and extract some informations without uploading it.

i created a formpanel that contains an uploadFile form but i don't know waht's next, how to get the complete path of the file so i can read/write with java io or how to retrieve the file or is there an alternatif solution, thank you.

Best Regards.

  • Welcome to [SO]. Please tell us what you already tried and what is failing. Thank you! – igr Apr 19 '13 at 19:31

2 Answers2

1

You can do it in some modern browsers using bleeding edge HTML5 apis for which you would need to use GWT JSNI code. There are no api's from GWT team as is.

HTML5 FileReader

FileReader includes four options for reading a file, asynchronously:

FileReader.readAsBinaryString(Blob|File) - The result property will contain the file/blob's data as a binary string.
FileReader.readAsText(Blob|File, opt_encoding) - The result property will contain the file/blob's data as a text string. 
FileReader.readAsDataURL(Blob|File) - The result property will contain the file/blob's data encoded as a data URL.
FileReader.readAsArrayBuffer(Blob|File) - The result property will contain the file/blob's data as an ArrayBuffer object.

Example of GWT wrapper over these - https://github.com/bradrydzewski/gwt-filesystem

You can read about it more from here - How to retrieve file from GWT FileUpload component?

Community
  • 1
  • 1
appbootup
  • 9,537
  • 3
  • 33
  • 65
  • As @colin said at my answer.its limited browser solution. – Suresh Atta Apr 19 '13 at 20:12
  • How can you assure that all the users will use the modern browsers ?? And what about server side validation?? – Suresh Atta Apr 19 '13 at 20:19
  • 1
    Since the user is asking for a solution without uploading files to server side, the only way (without flash) is using the `FileApi` which is only available in certain browsers (nowadays they have a big shared market). – Manolo Carrasco Moñino Apr 20 '13 at 15:38
-1

IMHO you cannot read it .

Due to security reasons javascript(gwt) doesn't have access to the system drives files.

http://en.wikipedia.org/wiki/JavaScript#Security

see Opening a file in local file system in javascript

In order to get the file you need to make a server call.

Instead you can do your validation server side and throw proper messages to user.

P.S : i am not considering modern browser concept.What happens if someone opened in other than so called modern browsers?? Will the programm runs same?? Its always better to do server side validation..

Community
  • 1
  • 1
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • We can use HTML5 FileReader api's. – appbootup Apr 19 '13 at 19:30
  • 2
    You can only use that in the limited set of browser that support it - for everything else, you must send it to the server (as this answer suggests), or use another plugin to read it (flash, etc). – Colin Alworth Apr 19 '13 at 20:00
  • 1
    I didn't downvote, I was agreeing with you, and trying to demonstrate that @SSR's proposal doesn't work in all situations. – Colin Alworth Apr 19 '13 at 20:47