-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Store different versions with the exact same filename but in different directories #1861
Comments
I just had an idea, maybe I could have |
@Silex what's your usecase? |
@thomasfedb: I store images, I need to store a "medium" version that is 800x600 and a "small" version that is 200x150. I want them to have this layout on the disk:
That is, I want to have the following resulting files:
It's because I have another tool that requires a directory containing only full-res pictures, and I find it silly to have the medium/small versions with a different filename if they are in different directories. |
I just found the hack needed for it to work: class AlbumImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
def store_dir
"/images/%s" % (version_name || 'original')
end
def filename
"%s.jpeg" % model.created_at.to_i if original_filename.present?
end
def full_filename(for_file)
if model.new_record?
super(for_file)
else
for_file
end
end
version :medium do
process resize_to_fill: [800, 600]
end
version :small, from_version: :medium do
process resize_to_fill: [200, 150]
end
end The idea is that carrierwave needs a different filename for the temporary thumbnails, but only when the record is not saved yet. Basically, once the file is saved A simple fix that'd remove the hack above could be to also use |
We're always interested in new contributions @Silex. Glad you found a solution! |
@thomasfedb: before I do, can you confirm that in EDIT: hum, unfortunately it seems that Current's what's working is |
Hi @Silex, you're going to have to investigate and read through the codebase. I'm not a long-standing CarrierWave developer, just somebody who volunteered to come on to look after the issues and PRs. |
Hello
I'm using carrierwave from master.
It looks like we cannot have the exact same filename for different versions.
If I upload a file, say "hello.jpg" and the associated model has id 123, I want it to be saved that way on the disk (the model.id is irrelevant here, it can be anything as long as it results in the exact same filename):
Here is what I tried:
It fails when creating the versions because I guess it deletes the same cache file twice (it works if I let the filename be different, with the version1_ or version2_ being prefixed).
Also, someone at http://stackoverflow.com/questions/31729932/how-to-customize-version-filename-in-carrierwave seems to have the same problem.
The text was updated successfully, but these errors were encountered: