Closed Obvio closed 7 years ago
Hello, @Obvio! I just added new option "rename" which can change the file name before upload starts!
var count = 0;
var uploader = new SocketIOFile(socket, {
overwrite: false
rename: function(filename) {
var split = filename.split('.'); // split filename by .(extension)
var fname = split[0]; // filename without extension
var ext = split[1];
return `${fname}_${count++}.${ext}`;
}
});
You can now change the file name using 'rename' option, returning value will be the name of a file. Enjoy ;)
Oh, don't forget to update socket.io-file to 2.0.1 !
thanks! works great! by the way, it might be better using
var path = require('path');
...
rename: function(filename) {
var fname = path.parse(filename).name;
var ext = path.parse(filename).ext;
return `${fname}_${count++}.${ext}`;
}
because a file name can have .
in it.
@Obvio Nice point :) I will change the example in document later, thanks! Anyway If you like this module, don't forget to give me a star!
Thanks for this!
I wanted to know if it's possible to change the uploaded file name before it writes to the server, i want to always allow uploads with
{overwrite:false}
.Thanks again!