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 + '%'); }); };