aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/active_file/blob.rb19
-rw-r--r--lib/active_file/migration.rb4
2 files changed, 18 insertions, 5 deletions
diff --git a/lib/active_file/blob.rb b/lib/active_file/blob.rb
index 817617ecaf..75e606b68b 100644
--- a/lib/active_file/blob.rb
+++ b/lib/active_file/blob.rb
@@ -18,8 +18,8 @@ class ActiveFile::Blob < ActiveRecord::Base
def build_after_upload(data:, filename:, content_type: nil, metadata: nil)
new.tap do |blob|
blob.filename = name
- blob.content_type = Marcel::MimeType.for(data, name: name, declared_type: content_type)
- blob.data = data
+ blob.content_type = content_type # Marcel::MimeType.for(data, name: name, declared_type: content_type)
+ blob.upload data
end
end
@@ -28,14 +28,27 @@ class ActiveFile::Blob < ActiveRecord::Base
end
end
+ # We can't wait until the record is first saved to have a key for it
+ def key
+ self[:key] ||= self.class.generate_unique_secure_token
+ end
def filename
Filename.new(filename)
end
+ def upload(data)
+ site.upload key, data
+ end
+
+ def download
+ site.download key
+ end
+
+
def delete
- site.delete(key)
+ site.delete key
end
def purge
diff --git a/lib/active_file/migration.rb b/lib/active_file/migration.rb
index 6e5ed0c997..7a424722e0 100644
--- a/lib/active_file/migration.rb
+++ b/lib/active_file/migration.rb
@@ -1,7 +1,7 @@
-class ActiveFile::CreateBlobs < ActiveRecord::Migration[5.2]
+class ActiveFile::CreateBlobs < ActiveRecord::Migration[5.1]
def change
create_table :active_file_blobs do |t|
- t.string :token
+ t.string :key
t.string :filename
t.string :content_type
t.integer :byte_size