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

File overwrite management if there is already one with the same name #874

Closed
nobady90 opened this issue May 28, 2018 · 3 comments
Closed
Labels

Comments

@nobady90
Copy link

Q A
Symfony Version 3.3.*
VichUploader Bundle Version 1.6

Support Question

I'm looking for a way to avoid overwriting a file when the user loads a file with the same name as a file already present and uploaded to the server.

To do this, however, I would like the user not to notice anything, so without changing the name of the file that will be loaded.

I'm trying to do it through the Namers but I do not think there is way.

Practically:

  1. the user uploads a file with the same name equal to another file already loaded and present on the server.
  2. during loading the original name is changed with a random identifier but all in Back-End. (for example using the symfony UploadedFile)
  3. the user will see the file name equal to the loaded one without noticing any difference.

It's possible?
Thank you all.

@garak
Copy link
Collaborator

garak commented May 28, 2018

OrignameNamer is already providing such feature: it adds a uniqid() to client's original name.

@garak garak added the Question label May 28, 2018
@nobady90
Copy link
Author

Thank's @garak, I solved using both uniqid () saving it in a slug column, and the original name so as to show it to the user. (which at that point will not notice anything)
I close this issue, good work!

@DhiaDjobbi
Copy link

File Namer is the solution for this

At the moment there are several available namers:

  • Vich\UploaderBundle\Naming\UniqidNamer
    
  • Vich\UploaderBundle\Naming\OrignameNamer
    
  • Vich\UploaderBundle\Naming\PropertyNamer
    
  • Vich\UploaderBundle\Naming\HashNamer
    
  • Vich\UploaderBundle\Naming\Base64Namer
    
  • Vich\UploaderBundle\Naming\SmartUniqueNamer
    
  • Vich\UploaderBundle\Naming\SlugNamer
    

I personally use HashNamer with MD5:

        prodimage:
            uri_prefix: /prodimages
            upload_destination: '%kernel.project_dir%/public/prodimages'
            namer:
                service: Vich\UploaderBundle\Naming\HashNamer
                options: { algorithm: 'md5', length: 30 }

https://github.com/dustin10/VichUploaderBundle/blob/master/docs/namers.md

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

No branches or pull requests

3 participants