I have a socket.io client to whom socket.io server is listening in node.js.I want to upload a file to server by socket.io. because my socket.io client is under apache. and socket.io server is in node.js. I want to code uploading of file in node.js. But how i can send the file data to the node.js listening to socket.
I have tried the upload of a file using node.js server. This link is here but the this code does not use the socket.io with this. But my original project is using the socket.io.
http://rahulmehta1.wordpress.com/2011/04/26/uploading-a-file-in-node-js-by-formidable/
How can i do this with the socket.io server?
The checked answer is invalid as of Jul 3rd 2012.
Read by yourself this tutorial on NetTuts. This tutorial uses node.js and socket.io to upload a file.
Here is a npm module I wrote that will implement Socket.IO file uploading in your application:
All you need to give the module is your middleware, your socket, and the file input or drop zone used for uploading files. It will also save the files if you give it a directory. The module takes care of the rest.
I wrote a module for this purpose.
Here is an example of sending a file over socket.io: http://liamkaufman.com/blog/2012/02/11/12-pushing-files-to-the-browser-using-deliveryjs-socketio-and-nodejs/
I use socket.io to help provide security for uploading, i use a algorithms in node.js to produce a "upload" key,, and sent this key to the client. then the client is allowed to upload a file with it, also a upload url it provide with the key to upload to.
why i do this... i store files in a db and i figured this was a good way to help manage load on my servers