41

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.

Uploading a file in node.js by formidable

How can I do this with the socket.io server?

5 Answers 5

28

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.

2
  • Do you have any idea about maximum file size that we can upload Apr 4, 2016 at 8:37
  • 1
    Node/socket.io are stream based, take it with a grain of salt - but there should be no limits. Apr 14, 2016 at 3:48
13

I wrote a module for this purpose.

socket.io-stream

2
  • Do you have any idea how to make ios-client that uses it, thanx.
    – M.Othman
    Aug 26, 2014 at 9:44
  • Using this library was OK until now, I'm using the latest JSPM version and it's not working anymore.
    – calbertts
    Aug 4, 2016 at 3:17
12

Here is a npm module I wrote that will implement Socket.IO file uploading in your application:

Socket.IO File Upload

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.

1
  • @Github scroll down to bottom there is an working example.
    – Jan Bludau
    Aug 27, 2016 at 21:34
6

In May of 2014 with release version 1.0 of socket.IO, binary support has been added to the library.

Socket.IO now supports emitting Buffer (from Node.JS), Blob, ArrayBuffer and even File, as part of any datastructure

It's all due to low level api which is provided by engine.io.

5

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/

2
  • The OP wants to send a file to the server, not to the client as in this example.
    – Prestaul
    Sep 7, 2012 at 22:38
  • 1
    The library from that example (Delivery.js) claims support for bidirectional file transfers.
    – Rob W
    May 25, 2014 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.