-
Notifications
You must be signed in to change notification settings - Fork 1.7k
-
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
recreate_versions!(...)
ignores :from_version => ...
#1164
Comments
I have the same problems.But I don't know how to fix it. |
I was able to make this work by reimplementing the def recreate_versions!(*versions)
if versions.any?
removable_versions(versions).each { |name, v| v.remove! }
from_versions = versions.group_by { |v| self.class.versions[v][:options][:from_version] }
from_versions.each do |from, versions|
next if from.nil?
file = CarrierWave::SanitizedFile.new(self.versions[from.to_sym].file)
store_versions!(file, versions)
end
else
super(*versions)
end
end
def removable_versions(requested_versions)
# versions is a method defined by carrierwave
versions.select { |k, v| requested_versions.include?(k) }
end |
I can confirm this bug. the workaround from @andrewcohen does not work for me though. Some more info: It does not work when using |
Just stumbled over this. Sad, it is not fixed yet (confirming issue still exists using CarrierWave 0.10.0). It would make my code much cleaner. I saw this when I wanted to do some of my picture work over a background job - where several jobs do different manipulations (e.g. one does a resize another does some cropping stuff). With a working I am currently using CarrierWaves conditional-versions for achieving my goal:
and then:
Whereby |
May be related to #1602. |
EDIT: This hack worked for version I followed more or less @andrewcohen solution. I didn't overwrite recreate_versions though. That's because I don't want other people to be surprise if their method does not work as usual. class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::ImageOptimizer
include CarrierWave::RMagick
storage :fog
def recreate_versions_for!(*versions)
if versions.any?
removable_versions(versions).each { |name, v| v.remove! }
from_versions = versions.group_by { |v| self.class.versions[v][:options][:from_version] }
from_versions.each do |from, versions|
next if from.nil?
file = CarrierWave::SanitizedFile.new(self.versions[from.to_sym].file)
store_versions!(file, versions)
end
end
end
def removable_versions(requested_versions)
versions.select { |k, v| requested_versions.include?(k) }
end
# ...
end Be careful if you have multiple images chained one after the other. For example, the code below won't work if you try to recreate :thumb. version :xlarge do
...
end
version :large, from_version: :xlarge do
...
end
version :thumb, from_version: :large do
...
end So please make sure all of them have at most one dependency, for instance: version :xlarge do
...
end
version :large, from_version: :xlarge do
...
end
# vvvvvvv
version :thumb, from_version: :xlarge do
...
end Than you can call: a = Art.find(123)
# since xlarge only depends on the original file
art.image.recreate_versions!(:xlarge)
art.image.recreate_versions_regarding_from_version!(:large)
art.image.recreate_versions_regarding_from_version!(:thumb) |
For those who stumbled upon this issue, the hacks proposed by @fwuensche and @andrewcohen don't work starting from version 1.0.0 (didn't have chance to test it on earlier versions, sorry). However, I do feel like the fix should be quite easy to implement. I started my own research by reading the source code, but seems like I don't exactly understand some core concepts like caching etc. Does anyone here have some time to guide me over the source code and maybe help me doing a PR? Hope, I can get some attention from the team members 🙏 |
I've stumbled upon this as well. For me, at this moment it's good enough given that my files are on servers disk. I haven't checked if this works as expected if files are in S3 though. |
Having the following code:
CarrierWave works as expected when I assign the file for the first time.
It also works when I call
recreate_versions!
without any parameters.But when I call
recreate_versions!(:small)
, it ignores:from_version
and use the original file that was uploaded.I suspect the bug to be in the method
recreate_versions!
:https://github.com/carrierwaveuploader/carrierwave/blob/master/lib/carrierwave/uploader/versions.rb#L223
It passes
sanitized_file
tostore_versions!
which I suspect is the original file that was uploaded instead of being the cache version corresponding to:medium
The text was updated successfully, but these errors were encountered: