1

I'm trying to create a file upload through socket.io 1.0.4 and the last version of socket.io-stream. Anytime I try to emit ss(socket).emit('mediaupload', file); the event is executed on the client but not called on the server side. I don't get any debug or error messages. If I try to emit the event through socket.emit('mediaupload') the server gets the event.

Server declaration

ss(socket).on('mediaupload', function(stream, data) { debug('Data:', data); ... } 

I don't know what to try anymore.

uploadFile: function (fileWithMeta, callback_end, callback_data) { var file=fileWithMeta.file; var stream = ss.createStream(); log.log('File to Upload with stream: ', stream); ss(socket).emit('mediaupload', file); var blobStream = ss.createBlobReadStream(file); if (callback_end){ blobStream.on('end', function(e) { callback_end(e); }); } if (callback_data){ var uploadedSize=0; blobStream.on('data', function(chunk) { uploadedSize+=chunk.length; callback_data(Math.floor(uploadedSize / file.size * 100), uploadedSize, chunk); }); } blobStream.pipe(stream); } 

I read the input file over a angularjs directive.

angular.module('oo.util').directive('ooFileReader', ['ooLog', '$parse', function (log, $parse) { var slice = Array.prototype.slice; return { restrict: 'A', //scope: false, link: function (scope, element, attrs) { element.bind("change", function (e) { $parse(attrs.ooFileReader).assign(scope, e.target.files[0]); }); } };}]); 

part of the template

 <input name="fileupload" type="file" oo-file-reader="fileupload" multiple> 

Functioncall: uploadFile is called with the variavle $scope.fileupload

$scope.uploadFile=function(file){ log.log('Add File: ', file); websocket.uploadFile(file, function(){ log.log('Upload Finished!'); }, function(percentUploaded){ log.log('Uploading: ' + percentUploaded + '%'); }); }; 
2
  • I've just tried to run the example code (a bit modified) from NPM site, and it works fine with Socket.IO 1.0.4 and latest Socket.IO-stream. Can you show your full code? Commented Jul 7, 2014 at 17:39
  • I added the code to the main post. Commented Jul 7, 2014 at 23:48

2 Answers 2

1

After including the socket.io-stream script on the client as described here:

cp node_modules/socket.io-stream/socket.io-stream.js somewhere/public/ 

you can do something like the following:

function(file){ var stream = ss.createStream(); ss(socket).emit("stream", stream, {},function(){}) ss.createBlobReadStream(file).pipe(stream) } 
Sign up to request clarification or add additional context in comments.

Comments

0

According to the documentation, you have to emit stream, not file.

Try to replace

ss(socket).emit('mediaupload', file); 

with

ss(socket).emit('mediaupload', stream); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.