Tutorial :Can you use the JavaScript engine in web browsers to process local files?


I have a number of users with multi-megabyte files that need to be processed before they can be uploaded. I am trying to find a way to do this without having to install any executable software on their machines.

If every machine shipped with, say, Python it would be easy. I could have a Python script do everything. The only scripting language I can think of that's on every machine is JavaScript. However I know there are security restrictions that prevent reading and writing local files from web browsers.

Is there any way to use this extremely pervasive scripting language for general purpose computing tasks?

EDIT: To clarify the requirements, this needs to be a cross platform, cross browser solution. I believe that HTA is an Internet Explorer only technology (or that the Firefox equivalent is broken).


Would Google Gears work here? Yes, users have to install something, but I think the experience is fairly frictionless. And once it's installed, no more worries.


The application that I maintain and develop for work is an HTML Application or HTA, linked with a SQL Server 2005 backend. This allows various security restrictions to be "avoided". All the client-side components in the application are done with javascript, including writing files to locally mapped network drives and loading data into screens/pages in an AJAXy way.

Perhaps HTA could be helpful for your situation.


For an example of javascript accessing a local file, you might try taking a look at the source of TiddlyWiki, specifically the saveFile, mozillaSaveFile, and ieSaveFile functions. Just click the download link, open the html file it sends you, and search for those functions.

Of course, tiddlywiki is supposed to be used as a local file, not served over the web, so the methods it uses may only work locally.. But it might be a start.


Why not use a flash uploader?


Adobe Flex 4 lets you to open and process a file on a local machine: http://livedocs.adobe.com/flex/3/langref/flash/net/FileReference.html#load()

It's not exactly JavaScript, but hope that helps.


I believe you can accomplish this using the HTML5 File API.

It is supported in Opera, IE, Safari, Firefox, and Chrome.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »