views:

111

answers:

4

I'm writing a JavaScript application which should let the user to load & save files in his/her PC. To do so, I need a basic server used only to echo loaded and saved files between the client and the server, since JavaScript doesn't have direct access to files.

What's the most lightweight solution to this problem?

+1  A: 

It depends on what server-side language you are using. For PHP, this answer has a pretty good overview of what you need for the upload part.

To download the files, you just need a page that takes a file name, and writes the content of the file (getting it from whatever path you saved it in when you uploaded it).

Matthew Crumley
A: 

This is a server that you intend to somehow install on the client's PC? I'm not intimately familiar with the technology, but it sounds like this is exactly the sort of capability browsers are trying so hard to prevent - code from one domain executing state-changing functionality on another domain.

Could you persist the data on your server, then automate a file transfer?

Or, if this is a standalone application in javascript that you want to run in a browser without using the network, look at Flash/Flex from Adobe, with the AIR libraries; which are built to do what you're talking about. (Note: Actionscript is a strict superset of javascript.)

le dorfier
A: 

Are you looking for a light-weight web-server? In which case, something like thttpd would be suitable. It's extremely easy to compile, and the configuration required is minimal.

Another far more flexible option would be something like twisted, "an event-driven networking engine written in Python". You could write basically anything along these lines fairly reliably/robustly, I would imagine. This tutorial may be a good start.

As with many things, the simplest solution is usually the best.. If you can get away with transferring files to a "dumb" secondary web-server, and retrieving them as regular files, it's probably better than implementing your own server solution in Python/twisted (or similar)

dbr
A: 

You could use nginx

Jan Hancic