How to read local (Client) file with GWT? - javascript

I would like to use GWT to read and parse local csv file.
EDIT: Local file here means client file.
I know I can use HTML5 with javascript to achieve that, but I would like to use GWT to do it.
One way of doing it is by using JavaScript Native Interface (JSNI), however I think it beats the purpose of using GWT.
Another way of doing this would be upload the file to server, and send it back as a json. But I feel it's not the best way of doing it.
Please advise. Thanks.
EDIT: I intend to design a desktop app, so I try to avoid using any web-server scripting.

Using jsni doesn't beat the purpose of gwt, sometimes you need to use it as a wrapper to functionality not yet available in gwt or an external javascript library. Instead of writting jsni access to the file api you can use one of several third party libraries available that implement html5 file access, like http://code.google.com/p/lib-gwt-file

A quick search returned this SO question: Read text file in google GWT?
Although GWT doesn't support java.io.InputStream, it looks like you could make a request to your CSV File and then parse it.
Remember that if you will host on AppEngine, you won't have a filesystem available so you'll have to have the files hosted elsewhere.

Related

ReactJS - check the existence of local file using Javascript

I need to check a particular software (built by us) has been installed to the Operating system. If not need to show a proper alert message.
As an alternative solution I'm going to do something like this
After installing the software there will be file in a given path (ex: c:\mysoftware\config.txt)
If there is any way to to check the existence of this config.txt file from Javascript then I can create a function like isSoftwareInstalled() in my reactjs application.
Am i doing right thing? or is there any professional but simple way of doing this?
As far as I understand, you must be keeping this file somewhere on the server.
If you are using Node/Express in the backend, you can use the Node File System readFile method.
https://nodejs.dev/learn/reading-files-with-nodejs
If you use some other backend language, kindly use File API in that.
In case, you are wondering about client-side file read, this is not possible with JS.

Server-side template parsing

I'm currently exploring how to use HandlebarsJS via a server-side parser.
Unfortunately we are limited to using RhinoJS server.
I've searched high and low to find out how to use HandlebarsJS via the server side. I can see how to register a helper and various other things, but I'm curious to know if it's possible to parse a JS or HTML file and have the various portions of the file replaced with the server generated content?
I'm hoping this is possible without using something like node and optimistic that it's possible to parse the file just like you would do using PHP or CFML but using JS under RhinoJS instead.
Any suggestions greatly appreciated.

upload to JWPlayer platform from within browser using JavaScript

Can anyone of point me to a JavaScript library or a piece of code that implements uploading video file using JWPlayer Platform API? There is a PHP example on their site (link on this page):
http://support.jwplayer.com/customer/portal/articles/1435970-upload-videos-with-the-platform-api
but not much about the JavaScript approach.
I would be very grateful for any information that can save me time. It is hard to believe nobody has done this so far, but I could not find a JS library that does the upload. Thank you in advance.
There is no JavaScript approach for uploading files to the platform. Our API kits for this only use PHP or Python. Using JavaScript is not possible because you need to set your account's API Key/Secret, which would be exposed to the public if using JavaScript. It doesn't make sense to use JavaScript for this purpose.

Is there a way to read a local netcdf file from a web application?

We are building a web service for data analysis and would like to access netcdf files from the local machine where the browser is running. Javascript offers a file browser, but (for security reasons as I learned) it will automatically upload a file after selection, instead of allowing (read-only) access to it. This presents a show-stopper, because the netcdf files can be HUGE. Note, that the netcdf format and API explicitly allow slicing and extraction of individual variables, which is one reason why the format is so popular.
Now, some research into this issue revealed that the server-client architecture normally doesn't allow access to the local file structure to prevent spying. On the other hand, in HTML5 there is a file API which supports exactly the kind of operations we need -- except that you can access portions of a file by specifying byte ranges, but there is no netcdf API available; hence one would be left again with copying the entire file before being able to slice it on the server.
Of course, the other option are web services such as OpenDAP which are meant to do exactly what we want, i.e. access parts of a netcdf file over the internet. However, this of course requires that every user would have to install the OpenDAP server before they could access their local files from within the web service. (Or, at a minimum they would have to install a web server so that one could access the file via http://localhost/...).
So: does anyone know of a solution to read specific portions of a local netcdf file from a web application? Specifically, are there javascript tools available for this?
Currently you can use netcdfjs, that it's a javascript library that allows to read NetCDF v3 files. Because it's a NodeJS package you can run it server side, and for regular size files you can read it online, here you have an example.
There are no Javascript tools to read NetCDF, but there are Java libraries: http://www.unidata.ucar.edu/downloads/netcdf/index.jsp.
You could deploy a Java Applet to read the NetCDF file locally. From there you could have the Applet try to process the file, or communicate with a backend service, or even try to call on the Applet from Javascript: http://docs.oracle.com/javase/tutorial/deployment/applet/invokingAppletMethodsFromJavaScript.html.
There are no specific Javascript libs for reading NetCDF, as far as I know. But let me drop some thoughts:
As you say, you can install a local webserver, and use a server-side language to execute a program that reads the file in your disk. You could use a command-line software called ncdump-json. I intentionally wrote this software for that purpose.
You say that you don't want to install software like OpenDAP or webservers, but maybe a desktop app, a standalone .exe would be OK for you. Using node.js plus chromium (this is called nw.js) you have a program that is at the same time a nodejs server, and a chromium browser. This way you can write a web application that reads the data (e.g. using the embedded nodejs server and spawning ncdump-json...).
And now the simplest scenario, a 100% client-side solution... I think this can only be achieved using Javascript... or anything that can "compile to" Javascript. We need to have the netCDF libraries in Javascript, is that possible? I guess so. Emscripten is a LLVM-to-Javascript compiler, and netCDF is C so it has to be possible to compile it with clang/LLVM, therefore it has to be possible to use Emscripten to have a netCDF JS library version with almost no effort, without having to write from scratch (and also maintain) a JS port. If I'm not wrong, to random access the files there's the method slice in the html5 file api, so that should not be a problem.
Hope I helped.

How to parse a CSV file into an array in Javascript

From what i understand, This usually has to be done server side. However i have read that it is possible to point to the csv file in a .js file. This would be more useful to me as i am not messing around with server side code and stuff for this project and will be all on my local machine. I saw an article with example code to do this somewere however i can't locate that article atm. Anyone know how to do this?
To access any file from the system you have to use directX in IE or read up on how to use NPAPI for mozilla support.If you are willing to use HTML5, check out its filereader API here.

Categories

Resources