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

Client details async

Open xeroxstar opened this issue 6 years ago • 1 comments

Hello, The client details that returns to the browser after the upload is completed should have return promise also. for example:

let uploader = new siofu();
    uploader.on('saved', async (event) => {
        event.file.clientDetail = new Promise((x) => {
            x({data: 'hello world'});
        })
 });
 uploader.dir = "./uploads";
 uploader.listen(socket);

to solve it i edit few lines in server.js to make it work:

socket.emit(_getTopicName("_complete"), _wrapData({
			id: id,
			success: success,
			detail: typeof fileInfo.clientDetail.then === 'function' ? await fileInfo.clientDetail:fileInfo.clientDetail
}, "complete"));

i think it will be a nice option if we will have this in the module so devs will have more flexible way to work with the data. Anyway, it works great.

xeroxstar avatar May 31 '19 16:05 xeroxstar

Looks good. My only feedback is if you can make this work without the "await" keyword, then the same source can be used on older versions of Node.js. Can you open a PR?

sffc avatar May 31 '19 17:05 sffc