FEATURE: Add S3 etag value to uploads table (#6795)

This commit is contained in:
Vinoth Kannan
2019-01-04 11:46:22 +05:30
committed by Guo Xiang Tan
parent 3a04e04ccb
commit 75dbb98cca
8 changed files with 88 additions and 14 deletions

View File

@ -24,8 +24,21 @@ class S3Helper
def upload(file, path, options = {})
path = get_path_for_s3_upload(path)
s3_bucket.object(path).upload_file(file, options)
path
obj = s3_bucket.object(path)
etag = begin
if File.size(file) >= Aws::S3::FileUploader::FIFTEEN_MEGABYTES
options[:multipart_threshold] = Aws::S3::FileUploader::FIFTEEN_MEGABYTES
obj.upload_file(file, options)
obj.load
obj.etag
else
options[:body] = file
obj.put(options).etag
end
end
return path, etag
end
def remove(s3_filename, copy_to_tombstone = false)
@ -210,8 +223,12 @@ class S3Helper
File.join("uploads", RailsMultisite::ConnectionManagement.current_db, "/")
end
def s3_client
Aws::S3::Client.new(@s3_options)
end
def s3_resource
Aws::S3::Resource.new(@s3_options)
Aws::S3::Resource.new(client: s3_client)
end
def s3_bucket