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

Prevent file name conflicts due to misconfiguration #69

Open
dacook opened this issue Nov 17, 2021 · 0 comments
Open

Prevent file name conflicts due to misconfiguration #69

dacook opened this issue Nov 17, 2021 · 0 comments

Comments

@dacook
Copy link

dacook commented Nov 17, 2021

Is your feature request related to a problem? Please describe.
I just fixed a problem caused by a misconfiguration with file path. Multiple styles were being generated (:original plus one custom one), but :style wasn't present in the path setting, so a filename conflict occurred.
This resulted in file uploads to a cloud service failing at first (due to a 404 from second delete), then succeeding on second try (no delete request made). It took a long time to figure out why it was "intermittently" failing!!!

Describe the solution you'd like
If there is more than one style (including :original), I think :style should be a required element in the path. Can this be validated upon initialisation?

Describe alternatives you've considered
Alternatively we could update the documentation to point this out
Actually, the path variables and :original style should be more documented anyway.

Additional context
Example configuration that was failing:

has_attached_file :image, path: "images/products/:id_:updated_at.:extension",# <-- no :style
                          default_style: :normal,
                          styles: { 
                            normal: { # <-- new style defined, without realising that :original also exists by default
                              geometry: '600x600#',
                              format: 'jpg',
                              quality: 80
                            }
                          }

Dev log from first try:

[paperclip] deleting images/products/3855_1637107719.jpg
[paperclip] deleting images/products/3855_1637107719.jpg
   (1.9ms)  ROLLBACK
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

1 participant