·红宝石(2.3.3)
·Ruby on Rails(5.1.4)
·AWS Linux
·独角兽
·Nginx
·MySQL
·ImageMagick(带有yum的6.9.10-6 Q16 x86_64)
·CarrierWave(最新)
·Rmagick(最新)
应用程序/上传器/ thumbnail_uploader.rb
class ThumbnailUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
process :fix_exif_rotation
process resize_to_fit: [400, 400]
def fix_exif_rotation
manipulate! do |img|
img.auto_orient!
img = yield(img) if block_given?
img
end
end
def filename
super.chomp(File.extname(super)) + '.jpg' if original_filename.present?
end
def filename
"#{secure_token}.#{file.extension}" if original_filename.present?
end
def secure_token
media_original_filenames_var = :"@#{mounted_as}_original_filenames"
unless model.instance_variable_get(media_original_filenames_var)
model.instance_variable_set(media_original_filenames_var, {})
end
unless model.instance_variable_get(media_original_filenames_var).map{|k,v| k }.include? original_filename.to_sym
new_value = model.instance_variable_get(media_original_filenames_var).merge({"#{original_filename}": SecureRandom.uuid})
model.instance_variable_set(media_original_filenames_var, new_value)
end
model.instance_variable_get(media_original_filenames_var)[original_filename.to_sym]
end
def extension_white_list
%w(jpg jpeg gif png)
end
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
上传图像大约需要15秒。
请告诉我哪些文件与原因有关。 谢谢!