socketio-file-upload
socketio-file-upload copied to clipboard
Allow overwriting files
Unless I'm not seeing the option, it seems there is no way to allow the uploader to overwrite a file if it already exists.
@DaneEveritt , a couple of directions to go here.
Caveat that I'm looking at socketio-file-upload today, and it might have changed since you posted back on Jan 15, 2017.
Note that siofu detects existing file and adds a numeric suffix to the filename to ensure a unique name. I understand your desire to overwrite the existing file rather than create a new filename. A common strategy (at least what I'm doing) is to upload to a temp dir. I listen for the "saved" event from siofu server-side. The object returned tells me the new filename--the full path. My "saved" event handler then moves the file into a permanent location. In that code, I have full control over naming, overwriting, etc.
A 2nd strategy that I think would work from reading the docs...check out: https://github.com/vote539/socketio-file-upload#instanceuploadvalidatorevent-callback
In that callback, you get an object that tells you the filename being uploaded. In this handler, you could write code to see if the file already exists, and if so, delete it or rename it. This way, when siofu goes to save the file, it will not find an existing file.
I have not tested this. I use uploadValidator() to specify an upload directory specific to each file uploaded. I rely on siofu's meta support to include a bit of data that I use inside that method.
TroyWolf's post is correct. You can listen for the "saved" event and move the file if you like. Another option is to bypass all of siofu's file handling operations by setting uploader.dir
to null and listening for "progress" events, piping them to your own file writer stream.