How can i browse file without uploading in GXT? - gwt

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.

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?

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

Related

SLIM API - Offer Files to Download

I am using Slim API for my Project. I want to offer Files for Download (Mostly PDF files). I found several Ways sending out a public link to the file, which i dont want. I also found an Middleware for the Version 2.4 of Slim, but I am using 3.x.
I just want to access the Route e.g. /downloads/version/2183
And the a Downlod with this certain File ID should start. I have a Path to the File on the Server in a variable available.
The Basic Idea behind is different restrictions, which user can download the file - but i can do that myself - the problem where I am stuck is, how to bring the Download over the Route to the Clients Browser
Does anyone know how to achieve this?
Cheers,
Niklas
This is actually very easy.
Set the Proper Headers for the file on the Response Object
Read the contents of the file into the body of the Response Object
$app->get('/my/file', function ($req, $res, $args) {
return $res->withHeader('Content-Type', 'application/octet-stream')
->withHeader('Content-Disposition', 'attachment')
->write(file_get_contents("file.txt"));
});

Objective-C – Smart programming with dependencies

I have an iOS application that parses xml data from the web. I've setup it to parse some xml tags for me and then display some information in the application.
I do not own the xml data so it's not unlikely that the xml tags could change without my knowledge and then rendering my iOS application useless because I'm not able to parse the data with the wrong xml tags.
So instead of having the application crashing when (if) they change xml tags I was thinking of having the application send an e-mail in the background alerting that the xml tags have changed. Or something like that. Is that possible to do or is it even a smart solution to my problem?
Why don't you parse the XML file in your server side using any technology that you prefer, and provide your controlled XML file to your iOS application. That way you will have the full control over the XML tags that your application expects! If the other party changes the tags, you just re-write your server side program to handle the changes gracefully!

GWT: How do I read an Excel file that is included in my src folder?

I am trying to program in GWT (using Eclipse and the GWT Designer). I would like to be able to take an Excel file that I have already imported into my source folder, read it, and process the data. The data will be both text and numbers, but I am comfortable doing the conversions from String to other types.
I have seen something about RequestBuilder, but I'm not sure how to use that to read Excel. Or, is there another/better way to do this?
I am willing to convert the Excel file into something like a CSV is that is necessary.
You'll probably want to do the processing in your servlet with something like
http://jexcelapi.sourceforge.net/
or
http://poi.apache.org/
I am not sure if this is clear enough to you, but it is not possible to process the excel file in GWT at least not directly.
You have to process it on the backend/server.
It can't be done on he client side because even if you put the excel file in your source folder it is not available to the GWT compiled javascript code on the client machine.
If you use Java on your backend/server you can use one of the libraries danb suggested to process it on the server and then use RequestFactory or RPC to transmit it to the client/browser for further processing/displaying.

Create Byte Array from GWT File upload Input

I have a .NET web service that takes a byte array.
I have a GWT client where I want the user to select a file using the FileUpload control and send it to the web service via HTTP stream.
The file upload control contains a method to get the file path of the selected file. How can I then get that file and convert it to a byte array?
I'm open to suggestions on how to get the file to my web service, not quite sure the Byte array will work...
If you want to convert the file in GWT, meaning in the browser. It's not possible to do in the browser using only JavaScript. FileUpload is a html input type file upload can only send the file to a server as in submit a form. For security reasons browsers can't read files from your file system. (You could use a plugin like a flash plugin to get it to work, although I have no examples at hand).
If you want to send the file content to your webservice, you need to or upload it directly to the webservice or send it to another server, convert it and from that server submit it to your webservice or write or find some (flash) plugin that does it for you.
This link maybe helpful yo you How to convert a byte array to a string, and string to a byte array with GWT
The String(byte[] bytes) constructor and String.getBytes() method are not implemented by GWT JRE emulation String class.
This is not possible purely in Javascript(yet) but could be done with flash or a signed applet. Personally what I would do is create a signed applet that would be somewhere on the page but not visible. When the user selects a file to send to the server you would get the file location from the input and send it to the applet which will load the file and return the data to Javascript as a byte array. If you are flexable with changing the web service to accept multi-part form data then you can do so and just include the file upload field as part of a form and submit the form. Now what you want to do is possible with HTML5 and a demonstration can be seen here, so if you are capable of specifying that the users be using at least a semi-HTML5 compliant browser such as FF3.6 or Chrome 6 you may be in luck.

Launching a GWT module when clicking on an XML

Greetings,
I'm looking for a way to launch a GWT module when a user clicks on an XML file and have the module consume the xml data. Ideally I would like to render the XML in a rich manner and would prefer to use GWT controls instead of having to lay it out by hand via xslt + javascript.
I'm supposing one way would be to point the xml to a well known xslt that creates a simple html page that forces a redirect to the gwt module but how would I transfer the xml data to said module to allow for enhanced formatting?
Another way would be to have the process that produces the xml also include the bootstrap gwt module but it would be creating multiple bootstrap instances over time and pollute the user's directory.
The use case is that a user would run this app on their local machine which outputs an XML file. If they try and view the xml file in a browser, I'd like to have the GWT module take over and present the data accordingly. I would rather they not have to go to a page and upload the data manually.
Appreciate any ideas on the matter.
TIA
If it's something that runs on the user's machine, I would recommend to ship an executable, or generate a parallel HTML file to present the data. JavaScript run from file:/// will not be able to acces the filesystem.