Skip to content

Instantly share code, notes, and snippets.

View toddnestor's full-sized avatar

Todd D Nestor toddnestor

View GitHub Profile
# config/initializers/paperclip.rb
# If you want to disable paperclip attachments to S3 in the development environment,
# remove the comments from the "if" condition below and restart the server.
#if Rails.env.staging? || Rails.env.production?
Paperclip::Attachment.default_options[:storage] = :s3
Paperclip::Attachment.default_options[:s3_credentials] = {
:bucket => "app-#{Rails.env}",
:access_key_id => '<ACCESS_KEY_ID>',
:secret_access_key => '<SECRET_ACCESS_KEY>'
@hartfordfive
hartfordfive / verify_s3_file.rb
Created November 1, 2016 17:47
Check if file exists in S3 bucket with Ruby aws-sdk gem
require 'aws-sdk'
s3 = Aws::S3::Resource.new(
region: 'us-east-1',
credentials: Aws::InstanceProfileCredentials.new()
)
bucket = s3.bucket('my-daily-backups')
file = (DateTime.now).strftime("%Y.%m.%d-backup")
if bucket.object(file).exists?