Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data passed to server always undefined #46

Closed
cobaki opened this issue May 12, 2015 · 7 comments
Closed

Data passed to server always undefined #46

cobaki opened this issue May 12, 2015 · 7 comments

Comments

@cobaki
Copy link

cobaki commented May 12, 2015

Hi

I'm trying to use the latest socket.io-stream with socket.io v.1.3.5. I've set up the most basic example (as per the github page). Even though the event is handled correctly, I always get the error that stream has no method 'pipe' and that data is undefined. Socket.io itself runs without any issues. Tested on Chrome/Safari/Firefox.

ss(socket).on('file', function(stream, data) {
    var filename = path.basename(data.name);
    stream.pipe(fs.createWriteStream(filename));
});

Could there be any issues with the latest version of socket.io? (I'm also using the express framework on my nodejs server). I 'd love to use the library in my project, any help is apreciated.

@nkzawa
Copy link
Owner

nkzawa commented May 12, 2015

Can you post client side too?

@cobaki
Copy link
Author

cobaki commented May 12, 2015

I'm using angularjs and a custom directive to get the file. But I've also tested with jQuery and the example you provide. In both cases the issue persits.

$('#file').change(function(e) {
    var file = e.target.files[0];
    var stream = ss.createStream();

    // upload a file to the server. 
    ss(socket).emit('file', stream, {size: file.size});
    ss.createBlobReadStream(file).pipe(stream);
});

Getting the file size and creating the stream works just fine. The 'file' event is emitted correctly as well, it's just that on the server side I'm not getting any data...

@nkzawa
Copy link
Owner

nkzawa commented May 12, 2015

hmm, I tested the latest version again and it works good for me.

How did you load socket.io-stream on client side?
What kind of errors do you get actually?
Can you post dump of logs if possible ?

// show logs
DEBUG=socket.io-stream* node your-server.js

@cobaki
Copy link
Author

cobaki commented May 12, 2015

Thank you for your quick responses trying to help me! I've found my error: In angularjs, I set up a factory that was wrapping socket 'on' and 'emit' events in order to automatically inform the scope, this interfered with the streaming calls.

@nkzawa nkzawa closed this as completed May 12, 2015
@BilalBoulifa
Copy link

@cobaki I'm facing the same issue can you please explain me how it was resolved?

@cobaki
Copy link
Author

cobaki commented Feb 15, 2016

@fithwith be sure to create the stream ss(socket) on the socket that was returned by io.connect(...)and not the one returned by your factory function. I just stored a reference to the initial socket in my factory and used it anytime I had to create a stream.

@BilalBoulifa
Copy link

@cobaki thank you for your quick reply, I did the same but I'm still facing the issue.
I'm using angularjs with the module ui.router, the first time I open the page where I can upload files its working fine, I can upload multiple files without problem, but once I visit another page (state because I'm using ui.router) and come back again to the upload page then the problem appear, I'm using the socket given by io.connect(), I emit the event, the data pass to the server, the stream also pass, but once the server try to call stream.pipe then the message pipe undefined appear.
I don't know if you have an idea from where it can come, its a little bit different than your case because I'm receiving the data and the stream correctly.
if you have an idea it wil be more than welcome :) thank you again @cobaki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants