Sidekiq을 사용하여 백그라운드 프로세스에서 이미지를 S3에 업로드하려면 carrierwave_backgrounder을 사용하고 있습니다.CarrierWave : 원본 파일을 업로드하고 저장합니다 ... 원하지 않습니다.
여기 클래스 ...
class BackgroundUploader < CarrierWave::Uploader::Base
include ::CarrierWave::Backgrounder::Delay
include CarrierWave::RMagick
include CarrierWave::MimeTypes
process :set_content_type
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :fog
def store_dir
"uploads/backgrounds/#{model.id}"
end
def default_url
"/assets/default.jpg"
end
process :resize_to_fit => [1024, 1024]
process :convert => 'jpg'
process :fix_exif_rotation
def extension_white_list
%w(jpg jpeg png)
end
def filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path.to_s))
"#{@name}.#{file.extension}" if original_filename
end
# Rotates the image based on the EXIF Orientation & applies gaussian blur
def fix_exif_rotation
manipulate! do |img|
img.auto_orient!
img = yield(img) if block_given?
img = img.gaussian_blur(0.0, 20.0)
img
end
end
end
carrierwave_backgrounder.rb 내 background_uploader.rb입니다 :
CarrierWave::Backgrounder.configure do |c|
c.backend :sidekiq, queue: :carrierwave
end
background.rb 포함
mount_uploader :image, BackgroundUploader
process_in_background :image
그런 다음 sidekiq -q carrierwave
을 실행하여 배경 작업자를 시작합니다. 모두 잘 작동합니다! 파일을 업로드하면 대기열이 수락되어 작업을 시작합니다. ...
즉시 AWS S3 Console을 열면 원본 파일이 표시됩니다. 크기가 조정되지 않고 흐려지지 않습니다. 작업이 완료되면 S3가 새로 고쳐지고 크기가 변경되거나 흐려집니다. 이제 두 이미지가 거기에 있지만 흐리게 표시된 이미지 만 있으면 좋을 것입니다. 내 생각에 나는 ...
<%= image_tag(@background.image.to_s) %>
원본 파일을 표시합니다. 확인란을 선택하여 파일을 제거하면 S3에서 원본을 삭제해야하지만 삭제 된 버전은 그대로 유지됩니다. (작업이 완료된 후)
는 S3에 업로드하기 무슨...
- original.jpg는
짧은 이야기 : 원본 파일을 S3에 업로드하고 싶지 않습니다.
확장자가 ".jpg"인 파일에서 발생합니까? – Taavo
.jpg, .png 등으로 발생합니다. [wiki article here] (https://github.com/carrierwaveuploader/carrierwave/wiki/How-to%3A-Cleanup-original-file)을 참조하려고했습니다. -that-wasn % 27t-Uploaded-like-Tempfile)뿐만 아니라 행운을 빕니다. – gbdev