shrine 3.0.0.rc → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of shrine might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -66
- data/README.md +39 -1061
- data/doc/advantages.md +151 -148
- data/doc/attacher.md +12 -30
- data/doc/carrierwave.md +150 -115
- data/doc/changing_derivatives.md +5 -11
- data/doc/changing_location.md +8 -5
- data/doc/changing_storage.md +5 -2
- data/doc/creating_persistence_plugins.md +9 -6
- data/doc/creating_plugins.md +42 -22
- data/doc/creating_storages.md +4 -1
- data/doc/design.md +7 -5
- data/doc/direct_s3.md +9 -4
- data/doc/external/articles.md +50 -0
- data/doc/external/extensions.md +46 -0
- data/doc/external/misc.md +17 -0
- data/doc/getting_started.md +1038 -0
- data/doc/metadata.md +5 -3
- data/doc/multiple_files.md +55 -29
- data/doc/paperclip.md +206 -163
- data/doc/plugins/activerecord.md +26 -6
- data/doc/plugins/add_metadata.md +4 -2
- data/doc/plugins/atomic_helpers.md +4 -2
- data/doc/plugins/backgrounding.md +83 -44
- data/doc/plugins/cached_attachment_data.md +4 -2
- data/doc/plugins/column.md +4 -2
- data/doc/plugins/data_uri.md +10 -6
- data/doc/plugins/default_storage.md +5 -3
- data/doc/plugins/default_url.md +4 -2
- data/doc/plugins/delete_raw.md +4 -2
- data/doc/plugins/derivation_endpoint.md +63 -39
- data/doc/plugins/derivatives.md +13 -50
- data/doc/plugins/determine_mime_type.md +6 -4
- data/doc/plugins/download_endpoint.md +6 -3
- data/doc/plugins/dynamic_storage.md +4 -2
- data/doc/plugins/entity.md +6 -4
- data/doc/plugins/form_assign.md +4 -2
- data/doc/plugins/included.md +4 -2
- data/doc/plugins/infer_extension.md +6 -4
- data/doc/plugins/instrumentation.md +5 -3
- data/doc/plugins/keep_files.md +9 -2
- data/doc/plugins/metadata_attributes.md +5 -3
- data/doc/plugins/mirroring.md +4 -2
- data/doc/plugins/model.md +6 -4
- data/doc/plugins/module_include.md +4 -2
- data/doc/plugins/multi_cache.md +4 -2
- data/doc/plugins/persistence.md +5 -3
- data/doc/plugins/presign_endpoint.md +6 -2
- data/doc/plugins/pretty_location.md +5 -3
- data/doc/plugins/processing.md +4 -2
- data/doc/plugins/rack_file.md +8 -2
- data/doc/plugins/rack_response.md +6 -2
- data/doc/plugins/recache.md +4 -2
- data/doc/plugins/refresh_metadata.md +5 -3
- data/doc/plugins/remote_url.md +26 -5
- data/doc/plugins/remove_attachment.md +4 -2
- data/doc/plugins/remove_invalid.md +10 -2
- data/doc/plugins/restore_cached_data.md +9 -3
- data/doc/plugins/sequel.md +26 -6
- data/doc/plugins/signature.md +6 -4
- data/doc/plugins/store_dimensions.md +6 -4
- data/doc/plugins/tempfile.md +4 -2
- data/doc/plugins/upload_endpoint.md +6 -2
- data/doc/plugins/upload_options.md +6 -4
- data/doc/plugins/url_options.md +4 -2
- data/doc/plugins/validation.md +7 -3
- data/doc/plugins/validation_helpers.md +13 -10
- data/doc/plugins/versions.md +4 -8
- data/doc/processing.md +27 -9
- data/doc/refile.md +119 -127
- data/doc/release_notes/1.0.0.md +4 -0
- data/doc/release_notes/1.1.0.md +4 -0
- data/doc/release_notes/1.2.0.md +4 -0
- data/doc/release_notes/1.3.0.md +4 -0
- data/doc/release_notes/1.4.0.md +4 -0
- data/doc/release_notes/1.4.1.md +4 -0
- data/doc/release_notes/1.4.2.md +4 -0
- data/doc/release_notes/2.0.0.md +4 -0
- data/doc/release_notes/2.0.1.md +4 -0
- data/doc/release_notes/2.1.0.md +4 -0
- data/doc/release_notes/2.1.1.md +4 -0
- data/doc/release_notes/2.10.0.md +4 -0
- data/doc/release_notes/2.10.1.md +4 -0
- data/doc/release_notes/2.11.0.md +4 -0
- data/doc/release_notes/2.12.0.md +4 -0
- data/doc/release_notes/2.13.0.md +4 -0
- data/doc/release_notes/2.14.0.md +5 -1
- data/doc/release_notes/2.15.0.md +10 -6
- data/doc/release_notes/2.16.0.md +4 -0
- data/doc/release_notes/2.17.0.md +4 -0
- data/doc/release_notes/2.18.0.md +4 -0
- data/doc/release_notes/2.19.0.md +7 -4
- data/doc/release_notes/2.2.0.md +4 -0
- data/doc/release_notes/2.3.0.md +4 -0
- data/doc/release_notes/2.3.1.md +4 -0
- data/doc/release_notes/2.4.0.md +4 -0
- data/doc/release_notes/2.4.1.md +4 -0
- data/doc/release_notes/2.5.0.md +4 -0
- data/doc/release_notes/2.6.0.md +4 -0
- data/doc/release_notes/2.6.1.md +4 -0
- data/doc/release_notes/2.7.0.md +4 -0
- data/doc/release_notes/2.8.0.md +4 -0
- data/doc/release_notes/2.9.0.md +4 -0
- data/doc/release_notes/3.0.0.md +120 -38
- data/doc/retrieving_uploads.md +4 -1
- data/doc/securing_uploads.md +4 -1
- data/doc/storage/file_system.md +12 -4
- data/doc/storage/s3.md +4 -2
- data/doc/testing.md +27 -41
- data/doc/upgrading_to_3.md +105 -26
- data/doc/validation.md +8 -6
- data/lib/shrine/attacher.rb +2 -2
- data/lib/shrine/attachment.rb +7 -10
- data/lib/shrine/plugins/activerecord.rb +10 -10
- data/lib/shrine/plugins/add_metadata.rb +1 -3
- data/lib/shrine/plugins/atomic_helpers.rb +6 -8
- data/lib/shrine/plugins/backgrounding.rb +4 -6
- data/lib/shrine/plugins/cached_attachment_data.rb +1 -3
- data/lib/shrine/plugins/column.rb +2 -4
- data/lib/shrine/plugins/data_uri.rb +1 -3
- data/lib/shrine/plugins/default_storage.rb +1 -3
- data/lib/shrine/plugins/default_url.rb +1 -3
- data/lib/shrine/plugins/delete_raw.rb +1 -3
- data/lib/shrine/plugins/derivation_endpoint.rb +3 -4
- data/lib/shrine/plugins/derivatives.rb +2 -4
- data/lib/shrine/plugins/determine_mime_type.rb +1 -3
- data/lib/shrine/plugins/download_endpoint.rb +1 -3
- data/lib/shrine/plugins/dynamic_storage.rb +1 -3
- data/lib/shrine/plugins/entity.rb +25 -9
- data/lib/shrine/plugins/form_assign.rb +1 -3
- data/lib/shrine/plugins/included.rb +1 -3
- data/lib/shrine/plugins/infer_extension.rb +1 -3
- data/lib/shrine/plugins/instrumentation.rb +1 -3
- data/lib/shrine/plugins/keep_files.rb +1 -3
- data/lib/shrine/plugins/metadata_attributes.rb +1 -3
- data/lib/shrine/plugins/mirroring.rb +2 -1
- data/lib/shrine/plugins/model.rb +2 -4
- data/lib/shrine/plugins/module_include.rb +1 -3
- data/lib/shrine/plugins/multi_cache.rb +3 -3
- data/lib/shrine/plugins/presign_endpoint.rb +1 -3
- data/lib/shrine/plugins/pretty_location.rb +1 -3
- data/lib/shrine/plugins/processing.rb +1 -3
- data/lib/shrine/plugins/rack_file.rb +1 -3
- data/lib/shrine/plugins/rack_response.rb +1 -3
- data/lib/shrine/plugins/recache.rb +1 -3
- data/lib/shrine/plugins/refresh_metadata.rb +1 -3
- data/lib/shrine/plugins/remote_url.rb +1 -3
- data/lib/shrine/plugins/remove_attachment.rb +1 -3
- data/lib/shrine/plugins/remove_invalid.rb +1 -3
- data/lib/shrine/plugins/restore_cached_data.rb +1 -3
- data/lib/shrine/plugins/sequel.rb +10 -12
- data/lib/shrine/plugins/signature.rb +1 -3
- data/lib/shrine/plugins/store_dimensions.rb +1 -3
- data/lib/shrine/plugins/tempfile.rb +1 -3
- data/lib/shrine/plugins/upload_endpoint.rb +1 -3
- data/lib/shrine/plugins/upload_options.rb +1 -3
- data/lib/shrine/plugins/url_options.rb +1 -3
- data/lib/shrine/plugins/validation.rb +1 -3
- data/lib/shrine/plugins/validation_helpers.rb +1 -3
- data/lib/shrine/plugins/versions.rb +1 -3
- data/lib/shrine/storage/file_system.rb +1 -1
- data/lib/shrine/storage/linter.rb +1 -1
- data/lib/shrine/storage/memory.rb +2 -1
- data/lib/shrine/storage/s3.rb +3 -3
- data/lib/shrine/version.rb +1 -1
- metadata +8 -4
data/doc/carrierwave.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
title: Shrine for CarrierWave Users
|
3
|
+
---
|
2
4
|
|
3
5
|
This guide is aimed at helping CarrierWave users transition to Shrine, and it
|
4
6
|
consists of three parts:
|
@@ -7,10 +9,44 @@ consists of three parts:
|
|
7
9
|
2. Instructions how to migrate and existing app that uses CarrierWave to Shrine
|
8
10
|
3. Extensive reference of CarrierWave's interface with Shrine equivalents
|
9
11
|
|
10
|
-
##
|
12
|
+
## Overview
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
### Uploader
|
15
|
+
|
16
|
+
Shrine shares CarrierWave's concept of **uploaders**, classes which encapsulate
|
17
|
+
file attachment logic for different file types:
|
18
|
+
|
19
|
+
```rb
|
20
|
+
class ImageUploader < Shrine
|
21
|
+
# attachment logic
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
However, while CarrierWave uploaders are responsible for most of the
|
26
|
+
attachment logic (uploading to temporary/permanent storage, retrieving the
|
27
|
+
uploaded file, file validation, processing versions), Shrine distributes
|
28
|
+
these responsibilities across several core classes:
|
29
|
+
|
30
|
+
| Class | Description |
|
31
|
+
| :---- | :----------- |
|
32
|
+
| `Shrine` | handles uploads, metadata extraction, location generation |
|
33
|
+
| `Shrine::UploadedFile` | exposes metadata, implements downloading, URL generation, deletion |
|
34
|
+
| `Shrine::Attacher` | handles caching & storing, dirty tracking, persistence, versions |
|
35
|
+
|
36
|
+
Shrine uploaders themselves are functional: they receive a file on the input
|
37
|
+
and return the uploaded file on the output. There are no state changes.
|
38
|
+
|
39
|
+
```rb
|
40
|
+
uploader = ImageUploader.new(:store)
|
41
|
+
uploaded_file = uploader.upload(file, :store)
|
42
|
+
uploaded_file #=> #<Shrine::UploadedFile>
|
43
|
+
uploaded_file.url #=> "https://my-bucket.s3.amazonaws.com/store/kfds0lg9rer.jpg"
|
44
|
+
uploaded_file.download #=> #<File:/tmp/path/to/file>
|
45
|
+
```
|
46
|
+
|
47
|
+
### Storage
|
48
|
+
|
49
|
+
In CarrierWave, you configure storage in global configuration:
|
14
50
|
|
15
51
|
```rb
|
16
52
|
CarrierWave.configure do |config|
|
@@ -24,6 +60,9 @@ CarrierWave.configure do |config|
|
|
24
60
|
config.fog_directory = "my-bucket"
|
25
61
|
end
|
26
62
|
```
|
63
|
+
|
64
|
+
In Shrine, the configuration options are passed directly to the storage class:
|
65
|
+
|
27
66
|
```rb
|
28
67
|
Shrine.storages[:store] = Shrine::Storage::S3.new(
|
29
68
|
bucket: "my-bucket",
|
@@ -33,11 +72,11 @@ Shrine.storages[:store] = Shrine::Storage::S3.new(
|
|
33
72
|
)
|
34
73
|
```
|
35
74
|
|
36
|
-
|
37
|
-
|
38
|
-
temporary
|
39
|
-
|
40
|
-
|
75
|
+
#### Temporary storage
|
76
|
+
|
77
|
+
Where CarrierWave's temporary storage is hardcoded to disk, Shrine can use any
|
78
|
+
storage for temporary storage. So, if you have multiple servers or want to do
|
79
|
+
[direct uploads], you can use AWS S3 as temporary storage:
|
41
80
|
|
42
81
|
```rb
|
43
82
|
Shrine.storages = {
|
@@ -46,32 +85,52 @@ Shrine.storages = {
|
|
46
85
|
}
|
47
86
|
```
|
48
87
|
|
49
|
-
|
88
|
+
### Persistence
|
50
89
|
|
51
|
-
|
52
|
-
|
90
|
+
While CarrierWave persists only the filename of the original uploaded file,
|
91
|
+
Shrine persists storage and metadata information as well:
|
53
92
|
|
54
93
|
```rb
|
55
|
-
|
56
|
-
|
57
|
-
|
94
|
+
{
|
95
|
+
"id": "path/to/image.jpg",
|
96
|
+
"storage": "store",
|
97
|
+
"metadata": {
|
98
|
+
"filename": "nature.jpg",
|
99
|
+
"size": 4739472,
|
100
|
+
"mime_type": "image/jpeg"
|
101
|
+
}
|
102
|
+
}
|
58
103
|
```
|
59
104
|
|
60
|
-
|
61
|
-
|
62
|
-
`Shrine::UploadedFile` class which represents the uploaded file.
|
105
|
+
This way we have all information about uploaded files, without having to
|
106
|
+
retrieve the file from the storage.
|
63
107
|
|
64
108
|
```rb
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
109
|
+
photo.image.id #=> "path/to/image.jpg"
|
110
|
+
photo.image.storage_key #=> :store
|
111
|
+
photo.image.metadata #=> { "filename" => "...", "size" => ..., "mime_type" => "..." }
|
112
|
+
|
113
|
+
photo.image.original_filename #=> "nature.jpg"
|
114
|
+
photo.image.size #=> 4739472
|
115
|
+
photo.image.mime_type #=> "image/jpeg"
|
69
116
|
```
|
70
117
|
|
71
|
-
|
118
|
+
#### Location
|
119
|
+
|
120
|
+
CarrierWave persists only the filename of the uploaded file, and recalculates
|
121
|
+
the full location dynamically based on location configuration. This can be
|
122
|
+
dangerous, because if some component of the location happens to change, all
|
123
|
+
existing links might become invalid.
|
72
124
|
|
73
|
-
|
74
|
-
|
125
|
+
To avoid this, Shrine persists the full location on attachment, and uses it
|
126
|
+
when generating file URL. So, even if you change how file locations are
|
127
|
+
generated, existing files that are on old locations will still remain
|
128
|
+
accessible.
|
129
|
+
|
130
|
+
### Processing
|
131
|
+
|
132
|
+
CarrierWave uses a class-level DSL for generating versions, which internally
|
133
|
+
uses uploader subclassing and does in-place processing.
|
75
134
|
|
76
135
|
```rb
|
77
136
|
class ImageUploader < CarrierWave::Uploader::Base
|
@@ -91,6 +150,9 @@ class ImageUploader < CarrierWave::Uploader::Base
|
|
91
150
|
end
|
92
151
|
```
|
93
152
|
|
153
|
+
In contrast, in Shrine you perform processing on the instance level as a
|
154
|
+
functional transformation, which is a lot simpler and more flexible:
|
155
|
+
|
94
156
|
```rb
|
95
157
|
require "image_processing/mini_magick"
|
96
158
|
|
@@ -109,23 +171,45 @@ class ImageUploader < Shrine
|
|
109
171
|
end
|
110
172
|
```
|
111
173
|
|
112
|
-
|
113
|
-
issue, as it allows users to give arbitrary files to your processing tool, even
|
114
|
-
if you have validations. With Shrine you can perform processing after
|
115
|
-
validations.
|
174
|
+
#### Retrieving versions
|
116
175
|
|
117
|
-
|
118
|
-
|
176
|
+
When retrieving versions, CarrierWave returns a list of declared versions which
|
177
|
+
may or may not have been generated. In contrast, Shrine persists data of
|
178
|
+
uploaded processed files into the database (including any extracted metadata),
|
179
|
+
which then becomes the source of truth on which versions have been generated.
|
119
180
|
|
120
|
-
|
181
|
+
```rb
|
182
|
+
photo.image #=> #<Shrine::UploadedFile @id="original.jpg" ...>
|
183
|
+
photo.image_derivatives #=> {}
|
121
184
|
|
122
|
-
|
123
|
-
|
185
|
+
photo.image_derivatives! # triggers processing
|
186
|
+
photo.image_derivatives #=>
|
187
|
+
# {
|
188
|
+
# large: #<Shrine::UploadedFile @id="large.jpg" @metadata={"size"=>873232, ...} ...>,
|
189
|
+
# medium: #<Shrine::UploadedFile @id="medium.jpg" @metadata={"size"=>94823, ...} ...>,
|
190
|
+
# small: #<Shrine::UploadedFile @id="small.jpg" @metadata={"size"=>37322, ...} ...>,
|
191
|
+
# }
|
192
|
+
```
|
193
|
+
|
194
|
+
#### Reprocessing versions
|
195
|
+
|
196
|
+
Shrine doesn't have a built-in way of regenerating versions, because that has
|
197
|
+
to be written and optimized differently depending on what versions have changed
|
198
|
+
which persistence library you're using, how many records there are in the table
|
199
|
+
etc.
|
200
|
+
|
201
|
+
However, there is an extensive guide for [Managing Derivatives], which provides
|
202
|
+
instructions on how to make these changes safely and with zero downtime.
|
203
|
+
|
204
|
+
### Validation
|
205
|
+
|
206
|
+
File validation in Shrine is also instance-level, which allows using
|
207
|
+
conditionals:
|
124
208
|
|
125
209
|
```rb
|
126
210
|
class ImageUploader < CarrierWave::Uploader::Base
|
127
211
|
def extension_whitelist
|
128
|
-
%w[jpg jpeg
|
212
|
+
%w[jpg jpeg png webp]
|
129
213
|
end
|
130
214
|
|
131
215
|
def content_type_whitelist
|
@@ -143,91 +227,43 @@ class ImageUploader < Shrine
|
|
143
227
|
plugin :validation_helpers
|
144
228
|
|
145
229
|
Attacher.validate do
|
146
|
-
validate_extension %w[jpg jpeg gif png]
|
147
|
-
validate_mime_type %w[image/jpeg image/gif image/png]
|
148
230
|
validate_max_size 10*1024*1024
|
231
|
+
validate_extension %w[jpg jpeg png webp]
|
232
|
+
|
233
|
+
if validate_mime_type %w[image/jpeg image/png image/webp]
|
234
|
+
validate_max_dimensions [5000, 5000]
|
235
|
+
end
|
149
236
|
end
|
150
237
|
end
|
151
238
|
```
|
152
239
|
|
153
|
-
|
240
|
+
#### Custom metadata
|
154
241
|
|
155
|
-
|
156
|
-
plugins for both Sequel and ActiveRecord, but can also be used with just PORO
|
157
|
-
models.
|
242
|
+
With Shrine you can also extract and validate any custom metadata:
|
158
243
|
|
159
244
|
```rb
|
160
|
-
|
161
|
-
|
162
|
-
|
245
|
+
class VideoUploader < Shrine
|
246
|
+
plugin :add_metadata
|
247
|
+
plugin :validation
|
163
248
|
|
164
|
-
|
165
|
-
|
166
|
-
|
249
|
+
add_metadata :duration do |io|
|
250
|
+
FFMPEG::Movie.new(io.path).duration
|
251
|
+
end
|
167
252
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
end
|
173
|
-
```
|
174
|
-
```rb
|
175
|
-
class Photo < ActiveRecord::Base
|
176
|
-
include ImageUploader::Attachment(:image)
|
253
|
+
Attacher.validate do
|
254
|
+
if file.duration > 5*60*60
|
255
|
+
errors << "must not be longer than 5 hours"
|
256
|
+
end
|
257
|
+
end
|
177
258
|
end
|
178
259
|
```
|
179
260
|
|
180
|
-
### Attachment column
|
181
|
-
|
182
|
-
You models are required to have the `<attachment>_data` column, which Shrine
|
183
|
-
uses to save storage, location, and metadata of the uploaded file.
|
184
|
-
|
185
|
-
```rb
|
186
|
-
photo.image_data #=>
|
187
|
-
# {
|
188
|
-
# "storage": "store",
|
189
|
-
# "id": "photo/1/image/0d9o8dk42.png",
|
190
|
-
# "metadata": {
|
191
|
-
# "filename": "nature.png",
|
192
|
-
# "size": 49349138,
|
193
|
-
# "mime_type": "image/png"
|
194
|
-
# }
|
195
|
-
# }
|
196
|
-
|
197
|
-
photo.image.original_filename #=> "nature.png"
|
198
|
-
photo.image.size #=> 49349138
|
199
|
-
photo.image.mime_type #=> "image/png"
|
200
|
-
```
|
201
|
-
|
202
|
-
This is much more powerful than storing only the filename like CarrierWave
|
203
|
-
does, as it allows you to also store any additional metadata that you might
|
204
|
-
want to extract.
|
205
|
-
|
206
|
-
Unlike CarrierWave, Shrine will store this information for each processed
|
207
|
-
version, making them first-class citizens:
|
208
|
-
|
209
|
-
```rb
|
210
|
-
photo.image #=> #<Shrine::UploadedFile>
|
211
|
-
photo.image.width #=> 800
|
212
|
-
|
213
|
-
photo.image(:thumb) #=> #<Shrine::UploadedFile>
|
214
|
-
photo.image(:thumb).width #=> 300
|
215
|
-
```
|
216
|
-
|
217
|
-
Also, since CarrierWave stores only the filename, it has to recalculate the
|
218
|
-
full location each time it wants to generate the URL. That makes it really
|
219
|
-
difficult to move files to a new location, because changing how the location is
|
220
|
-
generated will now cause incorrect URLs to be generated for all existing files.
|
221
|
-
Shrine calculates the whole location only once and saves it to the column.
|
222
|
-
|
223
261
|
### Multiple uploads
|
224
262
|
|
225
|
-
Shrine doesn't have support for multiple uploads like
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
associations. Take a look at the [demo app] which shows how easy it is to
|
230
|
-
implement multiple uploads.
|
263
|
+
Shrine doesn't have support for multiple uploads out-of-the-box like
|
264
|
+
CarrierWave does. Instead, you can implement them using a separate table with a
|
265
|
+
one-to-many relationship to which the files will be attached. The [Multiple
|
266
|
+
Files] guide explains this setup in more detail.
|
231
267
|
|
232
268
|
## Migrating from CarrierWave
|
233
269
|
|
@@ -653,9 +689,10 @@ multipart or not.
|
|
653
689
|
|
654
690
|
### `CarrierWave::Storage::Fog`
|
655
691
|
|
656
|
-
You can use [`Shrine::Storage::S3`]
|
657
|
-
[`Shrine::Storage::GoogleCloudStorage`], or generic
|
658
|
-
storage. The reference will assume you're
|
692
|
+
You can use [`Shrine::Storage::S3`][S3] (built-in),
|
693
|
+
[`Shrine::Storage::GoogleCloudStorage`][shrine-gcs], or generic
|
694
|
+
[`Shrine::Storage::Fog`][shrine-fog] storage. The reference will assume you're
|
695
|
+
using S3 storage.
|
659
696
|
|
660
697
|
#### `:fog_credentials`, `:fog_directory`
|
661
698
|
|
@@ -704,11 +741,9 @@ Shrine allows you to override the S3 endpoint:
|
|
704
741
|
Shrine::Storage::S3.new(use_accelerate_endpoint: true, **options)
|
705
742
|
```
|
706
743
|
|
707
|
-
[
|
708
|
-
[
|
709
|
-
[
|
744
|
+
[Managing Derivatives]: https://shrinerb.com/docs/changing-derivatives
|
745
|
+
[direct uploads]: https://shrinerb.com/docs/getting-started#direct-uploads
|
746
|
+
[S3]: https://shrinerb.com/docs/storage/s3
|
747
|
+
[shrine-gcs]: https://github.com/renchap/shrine-google_cloud_storage
|
710
748
|
[shrine-fog]: https://github.com/shrinerb/shrine-fog
|
711
|
-
[
|
712
|
-
[`Shrine::Storage::S3`]: /doc/storage/s3.md#readme
|
713
|
-
[`Shrine::Storage::GoogleCloudStorage`]: https://github.com/renchap/shrine-google_cloud_storage
|
714
|
-
[`Shrine::Storage::Fog`]: https://github.com/shrinerb/shrine-fog
|
749
|
+
[Multiple Files]: https://shrinerb.com/docs/multiple-files
|
data/doc/changing_derivatives.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
id: changing-derivatives
|
3
|
+
title: Managing Derivatives
|
4
|
+
---
|
2
5
|
|
3
6
|
This guide shows how to add, create, update, and remove [derivatives] for an
|
4
7
|
app in production already handling file attachments, with zero downtime.
|
@@ -22,15 +25,6 @@ class Photo < ActiveRecord::Base
|
|
22
25
|
end
|
23
26
|
```
|
24
27
|
|
25
|
-
## Contents
|
26
|
-
|
27
|
-
* [Adding derivatives](#adding-derivatives)
|
28
|
-
* [Reprocessing all derivatives](#reprocessing-all-derivatives)
|
29
|
-
* [Reprocessing certain derivatives](#reprocessing-certain-derivatives)
|
30
|
-
* [Adding new derivatives](#adding-new-derivatives)
|
31
|
-
* [Removing derivatives](#removing-derivatives)
|
32
|
-
* [Backgrounding](#backgrounding)
|
33
|
-
|
34
28
|
## Adding derivatives
|
35
29
|
|
36
30
|
*Scenario: Your app is currently working only with original files, and you want
|
@@ -311,4 +305,4 @@ class MakeChangeJob
|
|
311
305
|
end
|
312
306
|
```
|
313
307
|
|
314
|
-
[derivatives]: /
|
308
|
+
[derivatives]: https://shrinerb.com/docs/plugins/derivatives
|
data/doc/changing_location.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
id: changing-location
|
3
|
+
title: Migrating File Locations
|
4
|
+
---
|
2
5
|
|
3
6
|
This guide shows how to migrate the location of uploaded files on the same
|
4
7
|
storage in production, with zero downtime.
|
@@ -56,10 +59,10 @@ Photo.find_each do |photo|
|
|
56
59
|
|
57
60
|
begin
|
58
61
|
attacher.atomic_persist # persist changes if attachment has not changed in the meantime
|
59
|
-
old_attacher.
|
62
|
+
old_attacher.destroy_attached # delete files on old location
|
60
63
|
rescue Shrine::AttachmentChanged, # attachment has changed during reuploading
|
61
64
|
ActiveRecord::RecordNotFound # record has been deleted during reuploading
|
62
|
-
attacher.
|
65
|
+
attacher.destroy_attached # delete now orphaned files
|
63
66
|
end
|
64
67
|
end
|
65
68
|
```
|
@@ -100,9 +103,9 @@ class MoveFilesJob
|
|
100
103
|
attacher.set_derivatives attacher.upload_derivatives(attacher.derivatives)
|
101
104
|
|
102
105
|
attacher.atomic_persist
|
103
|
-
old_attacher.
|
106
|
+
old_attacher.destroy_attached
|
104
107
|
rescue Shrine::AttachmentChanged, ActiveRecord::RecordNotFound
|
105
|
-
attacher&.
|
108
|
+
attacher&.destroy_attached
|
106
109
|
end
|
107
110
|
end
|
108
111
|
```
|
data/doc/changing_storage.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
id: changing-storage
|
3
|
+
title: Migrating File Storage
|
4
|
+
---
|
2
5
|
|
3
6
|
This guides shows how to move file attachments to a different storage in
|
4
7
|
production, with zero downtime.
|
@@ -104,4 +107,4 @@ Shrine.storages = {
|
|
104
107
|
- Shrine.plugin :mirroring, mirror: { store: :s3 } # mirror to :s3 storage
|
105
108
|
```
|
106
109
|
|
107
|
-
[mirroring backgrounding]: /
|
110
|
+
[mirroring backgrounding]: https://shrinerb.com/docs/plugins/mirroring#backgrounding
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
---
|
2
|
+
id: creating-persistence-plugins
|
3
|
+
title: Writing a Persistence Plugin
|
4
|
+
---
|
2
5
|
|
3
6
|
This guide explains some conventions for writing Shrine plugins that integrate
|
4
7
|
with persistence libraries such as Active Record, Sequel, ROM and Mongoid. It
|
@@ -118,12 +121,12 @@ module Shrine::Plugins::Raptor
|
|
118
121
|
end
|
119
122
|
```
|
120
123
|
|
121
|
-
[Writing a Plugin]: /
|
124
|
+
[Writing a Plugin]: https://shrinerb.com/docs/creating-plugins
|
122
125
|
[Active Record pattern]: https://www.martinfowler.com/eaaCatalog/activeRecord.html
|
123
|
-
[model]: /
|
124
|
-
[entity]: /
|
126
|
+
[model]: https://shrinerb.com/docs/plugins/model
|
127
|
+
[entity]: https://shrinerb.com/docs/plugins/entity
|
125
128
|
[Repository pattern]: https://martinfowler.com/eaaCatalog/repository.html
|
126
|
-
[backgrounding]: /
|
127
|
-
[atomic_helpers]: /
|
129
|
+
[backgrounding]: https://shrinerb.com/docs/plugins/backgrounding
|
130
|
+
[atomic_helpers]: https://shrinerb.com/docs/plugins/atomic_helpers
|
128
131
|
[activerecord]: /lib/shrine/plugins/activerecord.rb
|
129
132
|
[sequel]: /lib/shrine/plugins/sequel.rb
|