I am using rails, and have an image uploader that inherits from CarrierWave::Uploader::Base but includes CarrierWaveDirect::Uploader. We are using Fog as storage and AWS S3 as the provider. We use it for both direct and indirect uploads.
I have just bumped our CarrierWaveDirect gem above 0.0.16 and I see that in this version there was a change to the key method in the Uploader. It went from using the url to using the dynamically generated "#{mounted_as}_identifier" method to create the key:
0.0.15 functionality:
def key
return @key if @key.present?
if present?
self.key = URI.parse(URI.encode(url, " []+()")).path[1 .. -1] # explicitly set key
else
@key = "#{store_dir}/#{guid}/#{FILENAME_WILDCARD}"
end
@key
end
0.0.16 functionality:
def key
return @key if @key.present?
if present?
identifier = model.send("#{mounted_as}_identifier")
self.key = [store_dir, identifier].join("/")
else
guid = SecureRandom.uuid
@key = [store_dir, guid, FILENAME_WILDCARD].join("/")
end
@key
end
Since this change when we are uploading non-directly (file uploaded in the browser, assigned to model in question then saved) the uploader is unable to generate the correct identifier. The present?
check returns true
, I presume because there is a cached file assigned, but calling "#{mounted_as}_identifier"
on the model returns nil, because it hasn't written the key to the column yet.
When I don't include CarrierWaveDirect::Uploader, or if I use version 0.0.15, all works as expected. However, using them together means that non-direct uploads go to just '/uploads/uploads', and rewrite the same location with each upload.
Does anyone know if this is just a quirk of using both uploaders together, or if it's something we're doing wrong, or if it's a bug with the gem?
Any thoughts much appreciated.