socket.io-stream icon indicating copy to clipboard operation
socket.io-stream copied to clipboard

ss with angularjs?....O.o

Open JoseMontesRicardo opened this issue 9 years ago • 1 comments

JoseMontesRicardo avatar Jan 28 '16 04:01 JoseMontesRicardo

If you dont mind selecting the file first, and then uploading

    <input id="fileselector" type="file" onchange="angular.element(this).scope().uploadFile()" >

Angular function in your controller. (Without writing a directive, ...)

        $scope.uploadFile = function() {
            var ssocket = io.connect();
            var file = document.getElementById('fileselector').files[0];
            var stream = ss.createStream();

            // upload a file to the server. 
            ss(ssocket).emit('file', stream, {
                size: file.size,
                name: 'upload-file-name.jpg'
            });

            //ss.createBlobReadStream(file).pipe(stream);

            var blobStream = ss.createBlobReadStream(file);
            var size = 0;
            blobStream.on('data', function(chunk) {
                size += chunk.length;
                console.log(Math.floor(size / file.size * 100) + '%');
                // -> e.g. '42%'
            });
            blobStream.pipe(stream);
        };

This connects to the default socket on the server side, and a new ssocket in angular.

LaKing avatar Jan 31 '17 03:01 LaKing