switch aws client libraries

This commit is contained in:
r888888888
2015-07-13 18:17:31 -07:00
parent 63f4ecf0f1
commit 2c8cacd50e
4 changed files with 26 additions and 24 deletions

View File

@@ -14,25 +14,28 @@ class AmazonBackup < ActiveRecord::Base
def self.execute
last_id = AmazonBackup.last_id
credentials = Aws::Credentials.new(Danbooru.config.amazon_s3_access_key_id, Danbooru.config.amazon_s3_secret_access_key)
client = Aws::S3::Client.new(region: "us-west-2", credentials: credentials)
bucket = Danbooru.config.amazon_s3_bucket_name
Post.where("id > ?", last_id).limit(1000).order("id").each do |post|
AWS::S3::Base.establish_connection!(
:access_key_id => Danbooru.config.amazon_s3_access_key_id,
:secret_access_key => Danbooru.config.amazon_s3_secret_access_key,
:server => "s3.amazonaws.com"
)
if File.exists?(post.file_path)
base64_md5 = Base64.encode64(Digest::MD5.digest(File.read(post.file_path)))
AWS::S3::S3Object.store(File.basename(post.file_path), open(post.file_path, "rb"), Danbooru.config.amazon_s3_bucket_name, "Content-MD5" => base64_md5)
key = File.basename(post.file_path)
body = open(post.file_path, "rb")
client.put_object(bucket: bucket, key: key, body: body, content_md5: base64_md5)
end
if post.has_preview? && File.exists?(post.preview_file_path)
AWS::S3::S3Object.store("preview/#{post.md5}.jpg", open(post.preview_file_path, "rb"), Danbooru.config.amazon_s3_bucket_name)
key = "preview/#{post.md5}.jpg"
body = open(post.preview_file_path, "rb")
client.put_object(bucket: bucket, key: key, body: body)
end
if File.exists?(post.large_file_path)
AWS::S3::S3Object.store("large/#{post.md5}.#{post.large_file_ext}", open(post.large_file_path, "rb"), Danbooru.config.amazon_s3_bucket_name)
key = "large/#{post.md5}.#{post.large_file_ext}"
body = open(post.large_file_path, "rb")
client.put_object(bucket: bucket, key: key, body: body)
end
AmazonBackup.update_id(post.id)