This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIZES = [%w[small S], %w[medium M], %w[large L], %w[extra_large EL]] | |
SIZES.each do |size| | |
upload_and_delete_local_file(key, image, size.first, size.last) | |
end | |
def upload_and_delete_local_file(key, image, size, file_size) | |
obj = S3.bucket('unikaihatsu-s3').object(key.gsub 'original', size) | |
obj.upload_file(Rails.public_path.join("#{file_size}_#{image.img_file_name}"), acl:'public-read') | |
File.delete(Rails.public_path.join("#{file_size}_#{image.img_file_name}")) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SIZES_ARR = [[167, 200, 'S'], [325, 390, 'M'], [625, 750, 'L']] | |
SIZES_ARR.each do |size_data| | |
resize_image(cropped_img, size_data.first, size_data.second, size_data.last) | |
end | |
def resize_image(image, width, height, size) | |
image.resize_to_fill(width, height).write(Rails.public_path.join("#{size}_#{self.img_file_name}")) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_attached_file :img, | |
styles: { small: '167x200#', medium: '325x390#', large: '625x750#' }, | |
default_url: '/assets/images/missing_product.png', | |
s3_region: ENV['AWS_REGION'], | |
storage: :s3, | |
s3_protocol: :https, | |
s3_credentials: "#{Rails.root}/config/amazon_s3.yml", | |
url: ':s3_domain_url', | |
path: '/hyper-image/bumon-code/:style/:id/:filename', | |
s3_host_alias: 'https://s3-ap-northeast-1.amazonaws.com/' |
NewerOlder