Skip to content

Instantly share code, notes, and snippets.

@NaiyaShah-BTC
Created August 13, 2018 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaiyaShah-BTC/0336585964ea67442c128d4b8331460b to your computer and use it in GitHub Desktop.
Save NaiyaShah-BTC/0336585964ea67442c128d4b8331460b to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment