paperclip_database_storage 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +9 -5
- data/app/controllers/paperclip_database_storage/attachments_controller.rb +2 -1
- data/app/models/paperclip_database_storage/attachment.rb +2 -2
- data/db/migrate/add_base64_encoded_to_paperclip_database_storage_attachments.rb +9 -0
- data/lib/paperclip_database_storage.rb +1 -0
- data/lib/paperclip_database_storage/storage/database.rb +2 -1
- data/lib/paperclip_database_storage/version.rb +1 -1
- metadata +2 -1
data/README.md
CHANGED
@@ -11,7 +11,7 @@ paperclip_database_storage requires [Paperclip](https://github.com/thoughtbot/pa
|
|
11
11
|
Installation
|
12
12
|
------------
|
13
13
|
|
14
|
-
paperclip_database_storage is distributed as a gem, and that is how it should be used in your app.
|
14
|
+
paperclip_database_storage is distributed as a gem, and that is how it should be used in your app.
|
15
15
|
|
16
16
|
Include the gem in your `Gemfile`, from rubygems:
|
17
17
|
|
@@ -21,6 +21,9 @@ Or, get the master branch from the repository:
|
|
21
21
|
|
22
22
|
gem 'paperclip_database_storage', :git => 'git://github.com/gokuu/paperclip_database_storage.git'
|
23
23
|
|
24
|
+
And afterwards, run the task to create the necessary migrations:
|
25
|
+
|
26
|
+
rake paperclip_database_storage:setup
|
24
27
|
Usage
|
25
28
|
-----
|
26
29
|
|
@@ -28,12 +31,12 @@ All you need to do is, when defining a [Paperclip](https://github.com/thoughtbot
|
|
28
31
|
|
29
32
|
```ruby
|
30
33
|
class MyModel < ActiveRecord::Base
|
31
|
-
has_attached_file :attachment,
|
32
|
-
:storage => :database,
|
34
|
+
has_attached_file :attachment,
|
35
|
+
:storage => :database,
|
33
36
|
:styles => {
|
34
37
|
:medium => "300x300>",
|
35
38
|
:thumb => "100x100>"
|
36
|
-
},
|
39
|
+
},
|
37
40
|
:url => "/:class/:attachment/:id/:style/:basename.:extension"
|
38
41
|
end
|
39
42
|
```
|
@@ -41,7 +44,8 @@ end
|
|
41
44
|
Remarks
|
42
45
|
-------
|
43
46
|
|
44
|
-
The migration defined by `paperclip_database_storage` contains several indexes, as every possible combination of the fields that can identify a single attachment. This should help getting an attachment as quickly as possible using any combination of parameters
|
47
|
+
The migration defined by `paperclip_database_storage` contains several indexes, as every possible combination of the fields that can identify a single attachment. This should help getting an attachment as quickly as possible using any combination of parameters.
|
48
|
+
As of version 3.0.7, the attachments are stored encoded in base64, to prevent loss of information. All previous stored attachments will still be usable as the table has a new field to indicate whether the attachment is stored base64-encoded.
|
45
49
|
|
46
50
|
Limitations
|
47
51
|
-----------
|
@@ -18,8 +18,9 @@ class PaperclipDatabaseStorage::AttachmentsController < ApplicationController
|
|
18
18
|
original_extension = File.extname(original_filename)
|
19
19
|
filename = params[:filename] || original_filename
|
20
20
|
filename = "#{filename}#{original_extension}" unless filename =~ /#{original_extension}$/
|
21
|
+
file_data = attachment.base64_encoded ? Base64.decode64(attachment.file_data) : attachment.file_data
|
21
22
|
|
22
|
-
send_data
|
23
|
+
send_data file_data,
|
23
24
|
:type => attachment.content_type,
|
24
25
|
:disposition => (attachment.content_type.strip =~ /^image/ ? 'inline' : 'attachment'),
|
25
26
|
:filename => filename
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module PaperclipDatabaseStorage
|
2
2
|
class Attachment < ActiveRecord::Base
|
3
3
|
belongs_to :attached, :polymorphic => true
|
4
|
-
|
5
|
-
attr_accessible :style, :file_data, :content_type, :file_size, :attachment_name
|
4
|
+
|
5
|
+
attr_accessible :style, :file_data, :content_type, :file_size, :attachment_name, :base64_encoded
|
6
6
|
|
7
7
|
def self.table_name
|
8
8
|
return 'paperclip_database_storage_attachments'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class AddBase64EncodedToPaperclipDatabaseStorageAttachments < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :paperclip_database_storage_attachments, :base64_encoded, :boolean, default: false
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.down
|
7
|
+
remove_column :paperclip_database_storage_attachments, :base64_encoded
|
8
|
+
end
|
9
|
+
end
|
@@ -65,7 +65,8 @@ module Paperclip
|
|
65
65
|
a.content_type = file.content_type
|
66
66
|
a.attachment_name = attachment_definitions.keys.first
|
67
67
|
a.file_size = file.size
|
68
|
-
a.file_data = file.read
|
68
|
+
a.file_data = Base64.encode64(file.read)
|
69
|
+
a.base64_encoded = true
|
69
70
|
end.save
|
70
71
|
end
|
71
72
|
@queued_for_write = {}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paperclip_database_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- app/controllers/paperclip_database_storage/attachments_controller.rb
|
41
41
|
- app/models/paperclip_database_storage/attachment.rb
|
42
42
|
- config/routes.rb
|
43
|
+
- db/migrate/add_base64_encoded_to_paperclip_database_storage_attachments.rb
|
43
44
|
- db/migrate/create_paperclip_database_storage_attachments.rb
|
44
45
|
- lib/paperclip_database_storage.rb
|
45
46
|
- lib/paperclip_database_storage/storage/database.rb
|