Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overwriting files #65

Open
DaneEveritt opened this issue Jan 16, 2017 · 2 comments
Open

Allow overwriting files #65

DaneEveritt opened this issue Jan 16, 2017 · 2 comments

Comments

@DaneEveritt
Copy link
Contributor

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.

@TroyWolf
Copy link

TroyWolf commented Dec 5, 2017

@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.

@sffc
Copy link
Owner

sffc commented Dec 5, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants