socketio-file-upload icon indicating copy to clipboard operation
socketio-file-upload copied to clipboard

Uploads tangled between clients

Open TimCody opened this issue 9 years ago • 3 comments

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.

TimCody avatar Feb 25 '16 23:02 TimCody

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?

MaffooBristol avatar Jul 08 '16 07:07 MaffooBristol

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.

vote539 avatar Jul 09 '16 20:07 vote539

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);
    });
    // ...
});

parshencev avatar Feb 28 '19 12:02 parshencev