sffc / socketio-file-upload

Uploads files to a Node.JS server using Socket.IO
321 stars 85 forks source link

Uploads tangled between clients #39

Open TimCody opened 8 years ago

TimCody commented 8 years ago

Some images I upload on one client get uploaded on the other clients browser. I'm not sure what is causing it. I've tried putting the server lines where the documentation said to put them var uploader = new siofu(); uploader.dir = 'images'; uploader.listen(socket); And also I tried putting them in an event that only fires once when the client connects. Neither worked.

MaffooBristol commented 8 years ago

Did you ever fix this issue? This type of thing tends to happen when variables aren't being scoped properly within a client and end up getting passed about, but if it is an SIOFU issue then that'd be pretty bad. Do you have the full code you're using?

vote539 commented 8 years ago

Make sure that you make a unique uploader instance for every socket connection. If you re-use the same uploader instance on the server for multiple connections, then you might observe this kind of behavior. For example, DON'T do this or any moral equivalent:

// BAD example
var uploader = new (require('socketio-file-upload'))();
io.sockets.on("connection", function(socket){
    uploader.listen(socket);
    // ...
});

You should instead make an instance for each and every connection:

// GOOD example
var SIOFU = require('socketio-file-upload');
io.sockets.on("connection", function(socket){
    var uploader = new SIOFU();
    uploader.listen(socket);
    // ...
});

If you can provide more sample code, that would make it easier to help you.

parshencev commented 5 years ago

it's working for me


var SIOFU = require('socketio-file-upload');
io.sockets.on("connection", function(socket){
    var uploader = new SIOFU();
    uploader.listen(socket);
    socket.uploaderDir = "./path/to/dir";
    uploader.on("start", e => {
       uploader.dir != socket.uploaderDir && (uploader.dir = socket.uploaderDir);
    });
    // ...
});