diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-01 12:47:13 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2017-07-01 12:47:29 +0200 |
commit | 182445e1b4b2e12542457ba32f255a0cc2f01910 (patch) | |
tree | 9287944c1431894bcb13c3ce71858edadf3761f4 /lib/active_file | |
parent | a239abb7fcaea4c271ea4bef031eda158d7cf8ad (diff) | |
download | rails-182445e1b4b2e12542457ba32f255a0cc2f01910.tar.gz rails-182445e1b4b2e12542457ba32f255a0cc2f01910.tar.bz2 rails-182445e1b4b2e12542457ba32f255a0cc2f01910.zip |
Test blobs with real db backend
Diffstat (limited to 'lib/active_file')
-rw-r--r-- | lib/active_file/blob.rb | 19 | ||||
-rw-r--r-- | lib/active_file/migration.rb | 4 |
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 |