paperclip_upload 1.1.0 → 1.2.2
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.
- checksums.yaml +4 -4
- data/.editorconfig +24 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +46 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +210 -0
- data/Guardfile +11 -0
- data/README.md +246 -0
- data/app/controllers/paperclip_upload/uploads_controller.rb +18 -1
- data/app/models/paperclip_upload/upload.rb +17 -2
- data/app/serializers/paperclip_upload/upload_serializer.rb +1 -1
- data/bin/rails +12 -0
- data/config/routes.rb +1 -0
- data/lib/generators/paperclip_upload/upload_controller/templates/controller.rb +18 -1
- data/lib/generators/paperclip_upload/upload_controller/upload_controller_generator.rb +33 -5
- data/lib/paperclip_upload/active_record_extension.rb +2 -2
- data/lib/paperclip_upload/version.rb +1 -1
- data/paperclip_upload.gemspec +34 -0
- metadata +96 -188
- data/spec/dummy/README.md +0 -1
- data/spec/dummy/Rakefile +0 -6
- data/spec/dummy/app/assets/javascripts/application.js +0 -13
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/controllers/application_controller.rb +0 -5
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/models/promotion.rb +0 -21
- data/spec/dummy/app/views/layouts/application.html.erb +0 -14
- data/spec/dummy/bin/bundle +0 -3
- data/spec/dummy/bin/rails +0 -4
- data/spec/dummy/bin/rake +0 -4
- data/spec/dummy/bin/setup +0 -29
- data/spec/dummy/config/application.rb +0 -26
- data/spec/dummy/config/boot.rb +0 -5
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -41
- data/spec/dummy/config/environments/production.rb +0 -79
- data/spec/dummy/config/environments/test.rb +0 -42
- data/spec/dummy/config/initializers/assets.rb +0 -11
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/dummy/config/initializers/inflections.rb +0 -16
- data/spec/dummy/config/initializers/mime_types.rb +0 -4
- data/spec/dummy/config/initializers/paperclip_upload.rb +0 -9
- data/spec/dummy/config/initializers/session_store.rb +0 -3
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -23
- data/spec/dummy/config/routes.rb +0 -3
- data/spec/dummy/config/secrets.yml +0 -22
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150612173816_create_paperclip_upload_uploads.paperclip_upload.rb +0 -8
- data/spec/dummy/db/migrate/20150612173817_add_attachment_file_to_uploads.paperclip_upload.rb +0 -12
- data/spec/dummy/db/migrate/20150613212501_create_promotions.rb +0 -8
- data/spec/dummy/db/migrate/20150613212609_add_attachment_photo_to_promotions.rb +0 -11
- data/spec/dummy/db/migrate/20150717201744_add_attachment_prefixed_file_one_to_promotions.rb +0 -11
- data/spec/dummy/db/migrate/20150717201754_add_attachment_prefixed_file_two_to_promotions.rb +0 -11
- data/spec/dummy/db/migrate/20150717202131_add_attachment_prefixed_file_to_promotions.rb +0 -11
- data/spec/dummy/db/schema.rb +0 -46
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +0 -5282
- data/spec/dummy/log/test.log +0 -39940
- data/spec/dummy/public/404.html +0 -67
- data/spec/dummy/public/422.html +0 -67
- data/spec/dummy/public/500.html +0 -66
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/system/promotions/photos/000/000/021/original/data +0 -0
- data/spec/dummy/spec/assets/bukowski.jpg +0 -0
- data/spec/dummy/spec/controllers/paperclip_upload/uploads_controller_spec.rb +0 -17
- data/spec/dummy/spec/models/paperclip_upload/upload_spec.rb +0 -25
- data/spec/dummy/spec/models/promotion_spec.rb +0 -110
- data/spec/dummy/tmp/promotions/1/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/1/data +0 -0
- data/spec/dummy/tmp/promotions/11/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/13/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/15/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/17/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/19/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/21/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/21/data +0 -0
- data/spec/dummy/tmp/promotions/3/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/5/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/7/bukowski.jpg +0 -0
- data/spec/dummy/tmp/promotions/9/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/10/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/12/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/14/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/18/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/2/Marilyn_Manson_imagen_003.jpg +0 -0
- data/spec/dummy/tmp/uploads/2/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/20/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/21/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/3/Marilyn_Manson_imagen_005.jpg +0 -0
- data/spec/dummy/tmp/uploads/4/Marilyn_Manson_imagen_005.jpg +0 -0
- data/spec/dummy/tmp/uploads/4/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/6/bukowski.jpg +0 -0
- data/spec/dummy/tmp/uploads/8/bukowski.jpg +0 -0
- data/spec/factories/paperclip_upload/uploads.rb +0 -7
- data/spec/factories/promotions.rb +0 -13
- data/spec/rails_helper.rb +0 -26
- data/spec/spec_helper.rb +0 -87
- data/spec/support/controller_helpers.rb +0 -16
- /data/{spec/dummy/log/RAILS_ENV=test.log → app/assets/images/paperclip_upload/.keep} +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d46199ef410968cd3e3f4f1635023ec9f396b3dd
|
|
4
|
+
data.tar.gz: 4093c1e4f3c47a4acf99da82ecbe38ce8b46917d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5ad84a18310b22af6d51fbb132f8be8a04ff39f3eab9e4dff15d33e11c2914a1ece16ff3052374dcf678b7b9608f1580dc8539bce79943e2d340470ba3114f4d
|
|
7
|
+
data.tar.gz: 704cb5f3b50e839cb9713d7b591cf486333306a8d2e37873ef742ee72486ea3295061f877dfd2d9515cb1f33af70265b0adb3fb553933054fade2c3e008694c9
|
data/.editorconfig
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# EditorConfig helps developers define and maintain consistent
|
|
2
|
+
# coding styles between different editors and IDEs
|
|
3
|
+
# editorconfig.org
|
|
4
|
+
|
|
5
|
+
root = true
|
|
6
|
+
|
|
7
|
+
[*]
|
|
8
|
+
|
|
9
|
+
# Change these settings to your own preference
|
|
10
|
+
indent_style = space
|
|
11
|
+
indent_size = 2
|
|
12
|
+
|
|
13
|
+
# We recommend you to keep these unchanged
|
|
14
|
+
end_of_line = lf
|
|
15
|
+
charset = utf-8
|
|
16
|
+
trim_trailing_whitespace = true
|
|
17
|
+
insert_final_newline = true
|
|
18
|
+
|
|
19
|
+
[*.js]
|
|
20
|
+
indent_style = space
|
|
21
|
+
indent_size = 2
|
|
22
|
+
|
|
23
|
+
[*.md]
|
|
24
|
+
trim_trailing_whitespace = false
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
All notable changes to this project will be documented in this file.
|
|
3
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
|
+
|
|
5
|
+
### v1.2.2
|
|
6
|
+
|
|
7
|
+
##### Fixed
|
|
8
|
+
* Removed tmp and spec files from gemspec definition.
|
|
9
|
+
|
|
10
|
+
### v1.2.1
|
|
11
|
+
|
|
12
|
+
##### Change
|
|
13
|
+
* A little refactor to controllers generator.
|
|
14
|
+
|
|
15
|
+
##### Fixed
|
|
16
|
+
* Autogenerated download url uses `identifier` attribute instead `id`.
|
|
17
|
+
|
|
18
|
+
### v1.2.0
|
|
19
|
+
|
|
20
|
+
##### Added
|
|
21
|
+
|
|
22
|
+
* Add file name, extension and download url to json response.
|
|
23
|
+
|
|
24
|
+
### v1.1.0
|
|
25
|
+
|
|
26
|
+
##### Added
|
|
27
|
+
|
|
28
|
+
* Allow multiple paperclip attributes on same host model to work with uploads.
|
|
29
|
+
|
|
30
|
+
### v1.0.0
|
|
31
|
+
|
|
32
|
+
##### Changed
|
|
33
|
+
|
|
34
|
+
* Use hashids gem to pass upload identifier in a more secure way.
|
|
35
|
+
|
|
36
|
+
##### Added
|
|
37
|
+
|
|
38
|
+
* Add uploads controller generator.
|
|
39
|
+
|
|
40
|
+
##### Removed
|
|
41
|
+
|
|
42
|
+
* Remove `additional_upload_endpoints` configuration option in favor of uploads controller generator.
|
|
43
|
+
|
|
44
|
+
### v0.1.0
|
|
45
|
+
|
|
46
|
+
* Initial release.
|
data/Gemfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
# Declare your gem's dependencies in paperclip_upload.gemspec.
|
|
4
|
+
# Bundler will treat runtime dependencies like base dependencies, and
|
|
5
|
+
# development dependencies will be added by default to the :development group.
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
# Declare any dependencies that are still in development here instead of in
|
|
9
|
+
# your gemspec. These might include edge Rails or gems from your path or
|
|
10
|
+
# Git. Remember to move these dependencies to your gemspec before releasing
|
|
11
|
+
# your gem to rubygems.org.
|
|
12
|
+
|
|
13
|
+
# To use a debugger
|
|
14
|
+
# gem 'byebug', group: [:development, :test]
|
|
15
|
+
|
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
paperclip_upload (1.2.2)
|
|
5
|
+
active_model_serializers (~> 0.9.3)
|
|
6
|
+
hashids (~> 1.0, >= 1.0.2)
|
|
7
|
+
paperclip (~> 4.2, >= 4.2.0)
|
|
8
|
+
rails (~> 4.2, >= 4.2.1)
|
|
9
|
+
responders (~> 2.1, >= 2.1.0)
|
|
10
|
+
|
|
11
|
+
GEM
|
|
12
|
+
remote: https://rubygems.org/
|
|
13
|
+
specs:
|
|
14
|
+
actionmailer (4.2.1)
|
|
15
|
+
actionpack (= 4.2.1)
|
|
16
|
+
actionview (= 4.2.1)
|
|
17
|
+
activejob (= 4.2.1)
|
|
18
|
+
mail (~> 2.5, >= 2.5.4)
|
|
19
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
20
|
+
actionpack (4.2.1)
|
|
21
|
+
actionview (= 4.2.1)
|
|
22
|
+
activesupport (= 4.2.1)
|
|
23
|
+
rack (~> 1.6)
|
|
24
|
+
rack-test (~> 0.6.2)
|
|
25
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
|
27
|
+
actionview (4.2.1)
|
|
28
|
+
activesupport (= 4.2.1)
|
|
29
|
+
builder (~> 3.1)
|
|
30
|
+
erubis (~> 2.7.0)
|
|
31
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
|
32
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
|
33
|
+
active_model_serializers (0.9.3)
|
|
34
|
+
activemodel (>= 3.2)
|
|
35
|
+
activejob (4.2.1)
|
|
36
|
+
activesupport (= 4.2.1)
|
|
37
|
+
globalid (>= 0.3.0)
|
|
38
|
+
activemodel (4.2.1)
|
|
39
|
+
activesupport (= 4.2.1)
|
|
40
|
+
builder (~> 3.1)
|
|
41
|
+
activerecord (4.2.1)
|
|
42
|
+
activemodel (= 4.2.1)
|
|
43
|
+
activesupport (= 4.2.1)
|
|
44
|
+
arel (~> 6.0)
|
|
45
|
+
activesupport (4.2.1)
|
|
46
|
+
i18n (~> 0.7)
|
|
47
|
+
json (~> 1.7, >= 1.7.7)
|
|
48
|
+
minitest (~> 5.1)
|
|
49
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
|
50
|
+
tzinfo (~> 1.1)
|
|
51
|
+
annotate (2.6.8)
|
|
52
|
+
activerecord (>= 3.2, <= 4.3)
|
|
53
|
+
rake (~> 10.4)
|
|
54
|
+
arel (6.0.0)
|
|
55
|
+
builder (3.2.2)
|
|
56
|
+
celluloid (0.16.0)
|
|
57
|
+
timers (~> 4.0.0)
|
|
58
|
+
climate_control (0.0.3)
|
|
59
|
+
activesupport (>= 3.0)
|
|
60
|
+
cocaine (0.5.7)
|
|
61
|
+
climate_control (>= 0.0.3, < 1.0)
|
|
62
|
+
coderay (1.1.0)
|
|
63
|
+
diff-lcs (1.2.5)
|
|
64
|
+
erubis (2.7.0)
|
|
65
|
+
factory_girl (4.5.0)
|
|
66
|
+
activesupport (>= 3.0.0)
|
|
67
|
+
factory_girl_rails (4.5.0)
|
|
68
|
+
factory_girl (~> 4.5.0)
|
|
69
|
+
railties (>= 3.0.0)
|
|
70
|
+
ffi (1.9.8)
|
|
71
|
+
formatador (0.2.5)
|
|
72
|
+
globalid (0.3.5)
|
|
73
|
+
activesupport (>= 4.1.0)
|
|
74
|
+
guard (2.12.5)
|
|
75
|
+
formatador (>= 0.2.4)
|
|
76
|
+
listen (~> 2.7)
|
|
77
|
+
lumberjack (~> 1.0)
|
|
78
|
+
nenv (~> 0.1)
|
|
79
|
+
notiffany (~> 0.0)
|
|
80
|
+
pry (>= 0.9.12)
|
|
81
|
+
shellany (~> 0.0)
|
|
82
|
+
thor (>= 0.18.1)
|
|
83
|
+
guard-compat (1.2.1)
|
|
84
|
+
guard-rspec (4.5.2)
|
|
85
|
+
guard (~> 2.1)
|
|
86
|
+
guard-compat (~> 1.1)
|
|
87
|
+
rspec (>= 2.99.0, < 4.0)
|
|
88
|
+
hashids (1.0.2)
|
|
89
|
+
hitimes (1.2.2)
|
|
90
|
+
i18n (0.7.0)
|
|
91
|
+
json (1.8.3)
|
|
92
|
+
listen (2.10.0)
|
|
93
|
+
celluloid (~> 0.16.0)
|
|
94
|
+
rb-fsevent (>= 0.9.3)
|
|
95
|
+
rb-inotify (>= 0.9)
|
|
96
|
+
loofah (2.0.2)
|
|
97
|
+
nokogiri (>= 1.5.9)
|
|
98
|
+
lumberjack (1.0.9)
|
|
99
|
+
mail (2.6.3)
|
|
100
|
+
mime-types (>= 1.16, < 3)
|
|
101
|
+
method_source (0.8.2)
|
|
102
|
+
mime-types (2.6.1)
|
|
103
|
+
mimemagic (0.3.0)
|
|
104
|
+
mini_portile (0.6.2)
|
|
105
|
+
minitest (5.7.0)
|
|
106
|
+
nenv (0.2.0)
|
|
107
|
+
nokogiri (1.6.6.2)
|
|
108
|
+
mini_portile (~> 0.6.0)
|
|
109
|
+
notiffany (0.0.6)
|
|
110
|
+
nenv (~> 0.1)
|
|
111
|
+
shellany (~> 0.0)
|
|
112
|
+
paperclip (4.3.0)
|
|
113
|
+
activemodel (>= 3.2.0)
|
|
114
|
+
activesupport (>= 3.2.0)
|
|
115
|
+
cocaine (~> 0.5.5)
|
|
116
|
+
mime-types
|
|
117
|
+
mimemagic (= 0.3.0)
|
|
118
|
+
pry (0.10.1)
|
|
119
|
+
coderay (~> 1.1.0)
|
|
120
|
+
method_source (~> 0.8.1)
|
|
121
|
+
slop (~> 3.4)
|
|
122
|
+
pry-rails (0.3.4)
|
|
123
|
+
pry (>= 0.9.10)
|
|
124
|
+
rack (1.6.1)
|
|
125
|
+
rack-test (0.6.3)
|
|
126
|
+
rack (>= 1.0)
|
|
127
|
+
rails (4.2.1)
|
|
128
|
+
actionmailer (= 4.2.1)
|
|
129
|
+
actionpack (= 4.2.1)
|
|
130
|
+
actionview (= 4.2.1)
|
|
131
|
+
activejob (= 4.2.1)
|
|
132
|
+
activemodel (= 4.2.1)
|
|
133
|
+
activerecord (= 4.2.1)
|
|
134
|
+
activesupport (= 4.2.1)
|
|
135
|
+
bundler (>= 1.3.0, < 2.0)
|
|
136
|
+
railties (= 4.2.1)
|
|
137
|
+
sprockets-rails
|
|
138
|
+
rails-deprecated_sanitizer (1.0.3)
|
|
139
|
+
activesupport (>= 4.2.0.alpha)
|
|
140
|
+
rails-dom-testing (1.0.6)
|
|
141
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
|
142
|
+
nokogiri (~> 1.6.0)
|
|
143
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
|
144
|
+
rails-html-sanitizer (1.0.2)
|
|
145
|
+
loofah (~> 2.0)
|
|
146
|
+
railties (4.2.1)
|
|
147
|
+
actionpack (= 4.2.1)
|
|
148
|
+
activesupport (= 4.2.1)
|
|
149
|
+
rake (>= 0.8.7)
|
|
150
|
+
thor (>= 0.18.1, < 2.0)
|
|
151
|
+
rake (10.4.2)
|
|
152
|
+
rb-fsevent (0.9.5)
|
|
153
|
+
rb-inotify (0.9.5)
|
|
154
|
+
ffi (>= 0.5.0)
|
|
155
|
+
recursive-open-struct (0.6.4)
|
|
156
|
+
responders (2.1.0)
|
|
157
|
+
railties (>= 4.2.0, < 5)
|
|
158
|
+
rspec (3.2.0)
|
|
159
|
+
rspec-core (~> 3.2.0)
|
|
160
|
+
rspec-expectations (~> 3.2.0)
|
|
161
|
+
rspec-mocks (~> 3.2.0)
|
|
162
|
+
rspec-core (3.2.3)
|
|
163
|
+
rspec-support (~> 3.2.0)
|
|
164
|
+
rspec-expectations (3.2.1)
|
|
165
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
166
|
+
rspec-support (~> 3.2.0)
|
|
167
|
+
rspec-mocks (3.2.1)
|
|
168
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
169
|
+
rspec-support (~> 3.2.0)
|
|
170
|
+
rspec-rails (3.2.2)
|
|
171
|
+
actionpack (>= 3.0, < 4.3)
|
|
172
|
+
activesupport (>= 3.0, < 4.3)
|
|
173
|
+
railties (>= 3.0, < 4.3)
|
|
174
|
+
rspec-core (~> 3.2.0)
|
|
175
|
+
rspec-expectations (~> 3.2.0)
|
|
176
|
+
rspec-mocks (~> 3.2.0)
|
|
177
|
+
rspec-support (~> 3.2.0)
|
|
178
|
+
rspec-support (3.2.2)
|
|
179
|
+
shellany (0.0.1)
|
|
180
|
+
shoulda-matchers (2.8.0)
|
|
181
|
+
activesupport (>= 3.0.0)
|
|
182
|
+
slop (3.6.0)
|
|
183
|
+
sprockets (3.2.0)
|
|
184
|
+
rack (~> 1.0)
|
|
185
|
+
sprockets-rails (2.3.2)
|
|
186
|
+
actionpack (>= 3.0)
|
|
187
|
+
activesupport (>= 3.0)
|
|
188
|
+
sprockets (>= 2.8, < 4.0)
|
|
189
|
+
sqlite3 (1.3.10)
|
|
190
|
+
thor (0.19.1)
|
|
191
|
+
thread_safe (0.3.5)
|
|
192
|
+
timers (4.0.1)
|
|
193
|
+
hitimes
|
|
194
|
+
tzinfo (1.2.2)
|
|
195
|
+
thread_safe (~> 0.1)
|
|
196
|
+
|
|
197
|
+
PLATFORMS
|
|
198
|
+
ruby
|
|
199
|
+
|
|
200
|
+
DEPENDENCIES
|
|
201
|
+
annotate (~> 2.6, >= 2.6.6)
|
|
202
|
+
factory_girl_rails (~> 4.5, >= 4.5.0)
|
|
203
|
+
guard (~> 2.12, >= 2.12.5)
|
|
204
|
+
guard-rspec (~> 4.5, >= 4.5.0)
|
|
205
|
+
paperclip_upload!
|
|
206
|
+
pry-rails (~> 0.3.3)
|
|
207
|
+
recursive-open-struct (~> 0.6.4)
|
|
208
|
+
rspec-rails (~> 3.2, >= 3.2.1)
|
|
209
|
+
shoulda-matchers (~> 2.8, >= 2.8.0)
|
|
210
|
+
sqlite3 (~> 1.3, >= 1.3.10)
|
data/Guardfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
guard :rspec, cmd: 'zeus rspec' do
|
|
2
|
+
watch(%r{^spec/.+_spec\.rb$})
|
|
3
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/dummy/spec/lib/#{m[1]}_spec.rb" }
|
|
4
|
+
watch('spec/spec_helper.rb') { "spec" }
|
|
5
|
+
|
|
6
|
+
# Rails example
|
|
7
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/dummy/spec/#{m[1]}_spec.rb" }
|
|
8
|
+
watch(%r{^spec/dummy/spec/support/(.+)\.rb$}) { "spec" }
|
|
9
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
|
10
|
+
watch('spec/rails_helper.rb') { "spec" }
|
|
11
|
+
end
|
data/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# Paperclip Upload
|
|
2
|
+
|
|
3
|
+
Rails engine to save [paperclip](https://github.com/thoughtbot/paperclip) attachments asynchronously. For example, if you have an `User` model with `avatar` paperclip attribute, you will:
|
|
4
|
+
|
|
5
|
+
1. Create a new upload instance to hold the avatar file temporarily.
|
|
6
|
+
1. Create a new user passing the upload id or instance as parameter.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add to your Gemfile...
|
|
11
|
+
|
|
12
|
+
```ruby
|
|
13
|
+
gem 'paperclip_upload'
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Run the installer:
|
|
17
|
+
|
|
18
|
+
```shell
|
|
19
|
+
$ rails generate paperclip_upload:install
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Then, add an attachment, as usually do, using paperclip.
|
|
23
|
+
|
|
24
|
+
```shell
|
|
25
|
+
$ rails generate paperclip user avatar
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Inside `User` model, you need to execute `has_attached_upload` instead the `has_attached_file` paperclip's method:
|
|
29
|
+
|
|
30
|
+
```ruby
|
|
31
|
+
class User < ActiveRecord::Base
|
|
32
|
+
has_attached_upload :avatar, path: ':rails_root/tmp/users/:id/:filename'
|
|
33
|
+
do_not_validate_attachment_file_type :avatar
|
|
34
|
+
end
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage
|
|
38
|
+
|
|
39
|
+
### Using `upload_identifier`
|
|
40
|
+
|
|
41
|
+
**First**: you need to save an upload instance.
|
|
42
|
+
The engine creates the `POST /uploads` endpoint to achieve this.
|
|
43
|
+
After perform a `POST` to `/uploads` with a `file` param, you will get this response:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"upload": {
|
|
48
|
+
"identifier": "rW6q2QZM",
|
|
49
|
+
"file_extension": "jpg",
|
|
50
|
+
"file_name": "90033441_BLO_20150607",
|
|
51
|
+
"download_url": "http://my-server.com/uploads/rW6q2QZM/download"
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Second**: supposing you have an `UsersController`, you need to perform a `POST /users` to create a new user passing the upload identifier you get previously.
|
|
57
|
+
|
|
58
|
+
```ruby
|
|
59
|
+
class UsersController < ApplicationController
|
|
60
|
+
def create
|
|
61
|
+
respond_with User.create(permitted_params)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def permitted_params
|
|
67
|
+
params.require(:user).permit(:upload_identifier)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Using `upload`
|
|
73
|
+
|
|
74
|
+
You can do something like this:
|
|
75
|
+
|
|
76
|
+
```ruby
|
|
77
|
+
class UsersController < ApplicationController
|
|
78
|
+
def create
|
|
79
|
+
@user = User.new
|
|
80
|
+
@user.upload = PaperclipUpload::Upload.create(file: params[:file])
|
|
81
|
+
@user.save!
|
|
82
|
+
respond_with @user
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Using prefix
|
|
88
|
+
|
|
89
|
+
You will need a way to match an upload resource with a specific attribute if you have two or more paperclip attributes on the same model. To do this, you can pass the option `upload: { use_prefix: true }` on `has_attached_upload` like this:
|
|
90
|
+
|
|
91
|
+
```ruby
|
|
92
|
+
class User < ActiveRecord::Base
|
|
93
|
+
has_attached_upload :avatar, path: ':rails_root/tmp/users/:id/:filename', upload: { use_prefix: true }
|
|
94
|
+
has_attached_upload :document, path: ':rails_root/tmp/users/:id/:filename', upload: { use_prefix: true }
|
|
95
|
+
has_attached_upload :photo, path: ':rails_root/tmp/users/:id/:filename'
|
|
96
|
+
end
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Then, in your controller...
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
class UsersController < ApplicationController
|
|
103
|
+
def create
|
|
104
|
+
respond_with User.create(permitted_params)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def permitted_params
|
|
110
|
+
params.require(:user).permit(:avatar_upload_identifier, :document_upload_identifier, :upload_identifier)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
or using the upload object...
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
class UsersController < ApplicationController
|
|
119
|
+
def create
|
|
120
|
+
@user = User.new
|
|
121
|
+
@user.avatar_upload = PaperclipUpload::Upload.create(file: params[:avatar])
|
|
122
|
+
@user.document_upload = PaperclipUpload::Upload.create(file: params[:document])
|
|
123
|
+
@user.upload = PaperclipUpload::Upload.create(file: params[:photo])
|
|
124
|
+
@user.save!
|
|
125
|
+
respond_with @user
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
> If you execute `has_attached_upload` method two or more times in same model with `upload: { use_prefix: false }` (false is the default value), you will be obligated to use the `upload: { use_prefix: true }` option. If you don't, an exception will be raised.
|
|
131
|
+
|
|
132
|
+
### Base64 Encoding
|
|
133
|
+
|
|
134
|
+
If you want to save base64 encoded attachments, you can execute the `allow_encoded_file_for` method:
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
class User < ActiveRecord::Base
|
|
138
|
+
has_attached_upload :avatar, path: ':rails_root/tmp/users/:id/:filename'
|
|
139
|
+
allow_encoded_file_for :avatar
|
|
140
|
+
do_not_validate_attachment_file_type :avatar
|
|
141
|
+
end
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
And then...
|
|
145
|
+
|
|
146
|
+
```ruby
|
|
147
|
+
class UsersController < ApplicationController
|
|
148
|
+
def create
|
|
149
|
+
respond_with User.create(permitted_params)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def permitted_params
|
|
155
|
+
params.require(:user).permit(:encoded_avatar)
|
|
156
|
+
# encoded_avatar param must hold the encoded file
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Creating your own `UploadsController`
|
|
162
|
+
|
|
163
|
+
You can generate your own `UploadsController` if for example:
|
|
164
|
+
|
|
165
|
+
* your controllers don't inherit from the `ApplicationController`
|
|
166
|
+
* you want to change the default route for `UploadsController`. (Also you can map the default controller with another route in your `routes.rb`)
|
|
167
|
+
* you want to add extra logic to the default `UploadsController`
|
|
168
|
+
|
|
169
|
+
Running...
|
|
170
|
+
|
|
171
|
+
```shell
|
|
172
|
+
$ rails generate paperclip_upload:upload_controller api/uploads api/base
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
You will get in `your_app/app/controllers/api/uploads_controller.rb`
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
class Api::UploadsController < Api::BaseController
|
|
179
|
+
self.responder = PaperclipUploadResponder
|
|
180
|
+
respond_to :json
|
|
181
|
+
|
|
182
|
+
def create
|
|
183
|
+
new_upload = PaperclipUpload::Upload.create(permitted_params)
|
|
184
|
+
set_download_url(new_upload)
|
|
185
|
+
respond_with new_upload, status: :created
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
def download
|
|
189
|
+
send_file(upload.file.path, type: upload.file_content_type, disposition: 'inline')
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
private
|
|
193
|
+
|
|
194
|
+
def permitted_params
|
|
195
|
+
params.permit(:file)
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def upload
|
|
199
|
+
@upload ||= PaperclipUpload::Upload.find_by_identifier(params[:identifier])
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
private
|
|
203
|
+
|
|
204
|
+
def set_download_url(_upload)
|
|
205
|
+
_upload.singleton_class.send(:attr_accessor, :download_url)
|
|
206
|
+
_upload.download_url = download_api_upload_url(identifier: _upload.identifier)
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
and the routes...
|
|
212
|
+
|
|
213
|
+
```ruby
|
|
214
|
+
post "api/uploads", to: "api/uploads#create", defaults: { format: :json }
|
|
215
|
+
get "api/uploads/:identifier/download", to: "api/uploads#download", defaults: { format: :json }, as: :download_api_upload
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## Configuration
|
|
219
|
+
|
|
220
|
+
You can change the engine configuration from `your_app/config/initializers/paperclip_upload.rb`
|
|
221
|
+
|
|
222
|
+
#### Configuration Options:
|
|
223
|
+
|
|
224
|
+
* `hash_salt`: The upload module uses a salt string to generate an unique hash for each instance. A salt string can be defined here to replace the default and increase the module's security.
|
|
225
|
+
|
|
226
|
+
* `use_prefix`: false by default. If true, you will need to pass `[host_model_paperclip_attribute_name]_+upload|upload_identifier` instead just `upload` or `upload_identifier` to the host model to use an upload resource.
|
|
227
|
+
|
|
228
|
+
## Contributing
|
|
229
|
+
|
|
230
|
+
1. Fork it
|
|
231
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
232
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
233
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
234
|
+
5. Create new Pull Request
|
|
235
|
+
|
|
236
|
+
## Credits
|
|
237
|
+
|
|
238
|
+
Thank you [contributors](https://github.com/platanus/paperclip_upload/graphs/contributors)!
|
|
239
|
+
|
|
240
|
+
<img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
|
|
241
|
+
|
|
242
|
+
paperclip_upload is maintained by [platanus](http://platan.us).
|
|
243
|
+
|
|
244
|
+
## License
|
|
245
|
+
|
|
246
|
+
Guides is © 2015 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
|
|
@@ -4,7 +4,13 @@ module PaperclipUpload
|
|
|
4
4
|
respond_to :json
|
|
5
5
|
|
|
6
6
|
def create
|
|
7
|
-
|
|
7
|
+
new_upload = PaperclipUpload::Upload.create(permitted_params)
|
|
8
|
+
set_download_url(new_upload)
|
|
9
|
+
respond_with new_upload, status: :created
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def download
|
|
13
|
+
send_file(upload.file.path, type: upload.file_content_type, disposition: 'inline')
|
|
8
14
|
end
|
|
9
15
|
|
|
10
16
|
private
|
|
@@ -12,5 +18,16 @@ module PaperclipUpload
|
|
|
12
18
|
def permitted_params
|
|
13
19
|
params.permit(:file)
|
|
14
20
|
end
|
|
21
|
+
|
|
22
|
+
def upload
|
|
23
|
+
@upload ||= PaperclipUpload::Upload.find_by_identifier(params[:identifier])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
def set_download_url(_upload)
|
|
29
|
+
_upload.singleton_class.send(:attr_accessor, :download_url)
|
|
30
|
+
_upload.download_url = download_url(identifier: _upload.identifier)
|
|
31
|
+
end
|
|
15
32
|
end
|
|
16
33
|
end
|
|
@@ -25,8 +25,19 @@ module PaperclipUpload
|
|
|
25
25
|
self.class.hashid.encode(self.id)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def
|
|
29
|
-
self.
|
|
28
|
+
def file_extension
|
|
29
|
+
return unless self.file.exists?
|
|
30
|
+
File.extname(self.file.original_filename).split('.').last
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def file_name
|
|
34
|
+
return unless self.file.exists?
|
|
35
|
+
self.file_file_name.gsub(".#{file_extension}", "")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.find_by_identifier(_identifier)
|
|
39
|
+
decoded_id = identifier_to_id(_identifier)
|
|
40
|
+
PaperclipUpload::Upload.find(decoded_id)
|
|
30
41
|
end
|
|
31
42
|
|
|
32
43
|
private
|
|
@@ -34,5 +45,9 @@ module PaperclipUpload
|
|
|
34
45
|
def self.hashid
|
|
35
46
|
Hashids.new(PaperclipUpload.hash_salt, IDENTIFIER_LENGTH)
|
|
36
47
|
end
|
|
48
|
+
|
|
49
|
+
def self.identifier_to_id(_identifier)
|
|
50
|
+
self.hashid.decode(_identifier).first
|
|
51
|
+
end
|
|
37
52
|
end
|
|
38
53
|
end
|
data/bin/rails
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
|
|
3
|
+
|
|
4
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
|
5
|
+
ENGINE_PATH = File.expand_path('../../lib/paperclip_upload/engine', __FILE__)
|
|
6
|
+
|
|
7
|
+
# Set up gems listed in the Gemfile.
|
|
8
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
|
9
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
|
10
|
+
|
|
11
|
+
require 'rails/all'
|
|
12
|
+
require 'rails/engine/commands'
|
data/config/routes.rb
CHANGED