lib/cloudinary/carrier_wave/storage.rb in cloudinary-1.0.50 vs lib/cloudinary/carrier_wave/storage.rb in cloudinary-1.0.51

- old
+ new

@@ -5,13 +5,13 @@ if uploader.is_main_uploader? case file when Cloudinary::CarrierWave::PreloadedCloudinaryFile if uploader.public_id && uploader.auto_rename_preloaded? @stored_version = file.version - uploader.rename + uploader.rename(nil, true) else - store_cloudinary_version(file.version) + store_cloudinary_identifier(file.version, file.filename) end return when Cloudinary::CarrierWave::CloudinaryFile return nil # Nothing to do when Cloudinary::CarrierWave::RemoteFile @@ -37,20 +37,34 @@ uploader.metadata = Cloudinary::Uploader.upload(data, params) if uploader.metadata["error"] raise Cloudinary::CarrierWave::UploadError.new(uploader.metadata["error"]["message"], uploader.metadata["error"]["http_code"]) end - store_cloudinary_version(uploader.metadata["version"]) if uploader.metadata["version"] + if uploader.metadata["version"] + filename = [uploader.metadata["public_id"], uploader.metadata["format"]].reject(&:blank?).join(".") + store_cloudinary_identifier(uploader.metadata["version"], filename) + end # Will throw an exception on error else raise CloudinaryException, "nested versions are not allowed." if (uploader.class.version_names.length > 1) # Do nothing - versions are not handled locally. end nil end + # @deprecated For backward compatibility def store_cloudinary_version(version) - name = "v#{version}/#{identifier.split("/", 2).last}" + if identifier.match(%r(^(v[0-9]+)/(.*))) + filename = $2 + else + filename = identifier + end + + store_cloudinary_identifier(version, filename) + end + + def store_cloudinary_identifier(version, filename) + name = "v#{version}/#{filename}" model_class = uploader.model.class column = uploader.model.send(:_mounter, uploader.mounted_as).send(:serialization_column) if defined?(ActiveRecord::Base) && uploader.model.is_a?(ActiveRecord::Base) primary_key = model_class.primary_key.to_sym if Rails.version >= "3.0"