1

My problem is as simple as annoying. I'm developing a Sailsjs app, and I would just like to use socket.io to upload a file.

I usually make use of Skipper which is the recommended Sails' upload handler, but the req.file() object stay undefined (though it work well with http requests).

1 Answers1

0

Skipper is not capable of that. At least I cannot find any proof in the documentation: https://github.com/balderdashy/skipper

Since sails@0.11.0 there is support for socket.io v1.2.1 which has support for binary data transfer: http://socket.io/blog/introducing-socket-io-1-0/#binary-support

You want to transfer data from client to server. However most example you find is the other way round, e.g. https://stackoverflow.com/a/24124966/401025:

Server sends image to client:

require('socket.io')(3000).on('connection', function(socket){
  require('fs').readFile('image.png', function(err, buf){
    socket.emit('image', { image: true, buffer: buf });
  });
});

Client receives image:

socket.on("image", function(image, buffer) {
   if(image){
       // do something with image
   }
});

I have not tested if it works from client to server. You have to try ;)

Community
  • 1
  • 1
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601