diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/active_file/blob.rb | 12 | ||||
-rw-r--r-- | lib/active_file/site.rb | 2 | ||||
-rw-r--r-- | lib/active_file/sites/disk_site.rb | 4 | ||||
-rw-r--r-- | lib/active_file/sites/gcs_site.rb | 4 | ||||
-rw-r--r-- | lib/active_file/sites/mirror_site.rb | 4 | ||||
-rw-r--r-- | lib/active_file/sites/s3_site.rb | 4 |
6 files changed, 15 insertions, 15 deletions
diff --git a/lib/active_file/blob.rb b/lib/active_file/blob.rb index 3cb98656f2..4af0551f99 100644 --- a/lib/active_file/blob.rb +++ b/lib/active_file/blob.rb @@ -11,16 +11,16 @@ class ActiveFile::Blob < ActiveRecord::Base class_attribute :site class << self - def build_after_upload(data:, filename:, content_type: nil, metadata: nil) + def build_after_upload(io:, filename:, content_type: nil, metadata: nil) new.tap do |blob| blob.filename = name blob.content_type = content_type # Marcel::MimeType.for(data, name: name, declared_type: content_type) - blob.upload data + blob.upload io end end - def create_after_upload!(data:, filename:, content_type: nil, metadata: nil) - build_after_upload(data: data, filename: filename, content_type: content_type, metadata: metadata).tap(&:save!) + def create_after_upload!(io:, filename:, content_type: nil, metadata: nil) + build_after_upload(io: io, filename: filename, content_type: content_type, metadata: metadata).tap(&:save!) end end @@ -38,8 +38,8 @@ class ActiveFile::Blob < ActiveRecord::Base end - def upload(data) - site.upload(key, data) + def upload(io) + site.upload(key, io) self.checksum = site.checksum(key) self.byte_size = site.byte_size(key) diff --git a/lib/active_file/site.rb b/lib/active_file/site.rb index 3340c16620..eb72ef39d4 100644 --- a/lib/active_file/site.rb +++ b/lib/active_file/site.rb @@ -3,7 +3,7 @@ class ActiveFile::Site def initialize end - def upload(key, data) + def upload(key, io) raise NotImplementedError end diff --git a/lib/active_file/sites/disk_site.rb b/lib/active_file/sites/disk_site.rb index 41b883498a..e5572073ed 100644 --- a/lib/active_file/sites/disk_site.rb +++ b/lib/active_file/sites/disk_site.rb @@ -9,9 +9,9 @@ class ActiveFile::Sites::DiskSite < ActiveFile::Site end - def upload(key, data) + def upload(key, io) File.open(make_path_for(key), "wb") do |file| - while chunk = data.read(65536) + while chunk = io.read(65536) file.write(chunk) end end diff --git a/lib/active_file/sites/gcs_site.rb b/lib/active_file/sites/gcs_site.rb index 71f065c608..f5f8696f56 100644 --- a/lib/active_file/sites/gcs_site.rb +++ b/lib/active_file/sites/gcs_site.rb @@ -8,8 +8,8 @@ class ActiveFile::Sites::GCSSite < ActiveFile::Site @bucket = @client.bucket(bucket) end - def upload(key, data) - bucket.create_file(data, key) + def upload(key, io) + bucket.create_file(io, key) end def download(key) diff --git a/lib/active_file/sites/mirror_site.rb b/lib/active_file/sites/mirror_site.rb index f734f3ebf9..051d139af1 100644 --- a/lib/active_file/sites/mirror_site.rb +++ b/lib/active_file/sites/mirror_site.rb @@ -5,8 +5,8 @@ class ActiveFile::Sites::MirrorSite < ActiveFile::Site @sites = sites end - def upload(key, data) - perform_across_sites :upload, key, data + def upload(key, io) + perform_across_sites :upload, key, io end def download(key) diff --git a/lib/active_file/sites/s3_site.rb b/lib/active_file/sites/s3_site.rb index 4ede843cb4..e13b609881 100644 --- a/lib/active_file/sites/s3_site.rb +++ b/lib/active_file/sites/s3_site.rb @@ -8,8 +8,8 @@ class ActiveFile::Sites::S3Site < ActiveFile::Site @bucket = @client.bucket(bucket) end - def upload(key, data) - object_for(key).put(body: data) + def upload(key, io) + object_for(key).put(body: io) end def download(key) |