shrine 2.15.0 → 2.16.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.

Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/doc/advantages.md +4 -0
  4. data/doc/plugins/activerecord.md +3 -2
  5. data/doc/plugins/add_metadata.md +4 -2
  6. data/doc/plugins/backgrounding.md +6 -4
  7. data/doc/plugins/backup.md +4 -2
  8. data/doc/plugins/cached_attachment_data.md +5 -3
  9. data/doc/plugins/copy.md +3 -1
  10. data/doc/plugins/data_uri.md +3 -2
  11. data/doc/plugins/default_storage.md +5 -2
  12. data/doc/plugins/default_url.md +4 -2
  13. data/doc/plugins/default_url_options.md +5 -2
  14. data/doc/plugins/delete_promoted.md +6 -4
  15. data/doc/plugins/delete_raw.md +12 -3
  16. data/doc/plugins/derivation_endpoint.md +17 -6
  17. data/doc/plugins/determine_mime_type.md +3 -2
  18. data/doc/plugins/direct_upload.md +4 -2
  19. data/doc/plugins/download_endpoint.md +46 -6
  20. data/doc/plugins/dynamic_storage.md +5 -2
  21. data/doc/plugins/hooks.md +3 -1
  22. data/doc/plugins/included.md +5 -2
  23. data/doc/plugins/infer_extension.md +5 -4
  24. data/doc/plugins/keep_files.md +5 -3
  25. data/doc/plugins/logging.md +4 -1
  26. data/doc/plugins/metadata_attribues.md +6 -3
  27. data/doc/plugins/migration_helpers.md +4 -2
  28. data/doc/plugins/module_include.md +4 -2
  29. data/doc/plugins/moving.md +6 -4
  30. data/doc/plugins/multi_delete.md +4 -2
  31. data/doc/plugins/parallelize.md +4 -2
  32. data/doc/plugins/parsed_json.md +5 -3
  33. data/doc/plugins/presign_endpoint.md +7 -5
  34. data/doc/plugins/pretty_location.md +4 -2
  35. data/doc/plugins/processing.md +3 -2
  36. data/doc/plugins/rack_file.md +4 -2
  37. data/doc/plugins/rack_response.md +26 -10
  38. data/doc/plugins/recache.md +7 -5
  39. data/doc/plugins/refresh_metadata.md +4 -2
  40. data/doc/plugins/remote_url.md +3 -1
  41. data/doc/plugins/remove_attachment.md +4 -2
  42. data/doc/plugins/remove_invalid.md +6 -3
  43. data/doc/plugins/restore_cached_data.md +8 -6
  44. data/doc/plugins/sequel.md +4 -1
  45. data/doc/plugins/signature.md +5 -3
  46. data/doc/plugins/store_dimensions.md +4 -2
  47. data/doc/plugins/tempfile.md +4 -2
  48. data/doc/plugins/upload_endpoint.md +4 -3
  49. data/doc/plugins/upload_options.md +4 -2
  50. data/doc/plugins/validation_helpers.md +4 -2
  51. data/doc/plugins/versions.md +3 -2
  52. data/doc/release_notes/2.15.0.md +2 -2
  53. data/doc/release_notes/2.16.0.md +52 -0
  54. data/doc/storage/s3.md +2 -2
  55. data/lib/shrine/plugins/_urlsafe_serialization.rb +2 -0
  56. data/lib/shrine/plugins/activerecord.rb +3 -0
  57. data/lib/shrine/plugins/add_metadata.rb +3 -0
  58. data/lib/shrine/plugins/backgrounding.rb +3 -0
  59. data/lib/shrine/plugins/backup.rb +3 -0
  60. data/lib/shrine/plugins/cached_attachment_data.rb +3 -0
  61. data/lib/shrine/plugins/copy.rb +3 -0
  62. data/lib/shrine/plugins/data_uri.rb +3 -0
  63. data/lib/shrine/plugins/default_storage.rb +3 -0
  64. data/lib/shrine/plugins/default_url.rb +3 -0
  65. data/lib/shrine/plugins/default_url_options.rb +3 -0
  66. data/lib/shrine/plugins/delete_promoted.rb +3 -0
  67. data/lib/shrine/plugins/delete_raw.rb +4 -1
  68. data/lib/shrine/plugins/derivation_endpoint.rb +144 -47
  69. data/lib/shrine/plugins/determine_mime_type.rb +3 -0
  70. data/lib/shrine/plugins/direct_upload.rb +3 -0
  71. data/lib/shrine/plugins/download_endpoint.rb +29 -29
  72. data/lib/shrine/plugins/dynamic_storage.rb +3 -0
  73. data/lib/shrine/plugins/hooks.rb +3 -0
  74. data/lib/shrine/plugins/included.rb +3 -0
  75. data/lib/shrine/plugins/infer_extension.rb +3 -0
  76. data/lib/shrine/plugins/keep_files.rb +3 -0
  77. data/lib/shrine/plugins/logging.rb +3 -0
  78. data/lib/shrine/plugins/metadata_attributes.rb +3 -0
  79. data/lib/shrine/plugins/migration_helpers.rb +3 -0
  80. data/lib/shrine/plugins/module_include.rb +3 -0
  81. data/lib/shrine/plugins/moving.rb +3 -0
  82. data/lib/shrine/plugins/multi_delete.rb +3 -0
  83. data/lib/shrine/plugins/parallelize.rb +5 -1
  84. data/lib/shrine/plugins/parsed_json.rb +3 -0
  85. data/lib/shrine/plugins/presign_endpoint.rb +3 -0
  86. data/lib/shrine/plugins/pretty_location.rb +3 -0
  87. data/lib/shrine/plugins/processing.rb +3 -0
  88. data/lib/shrine/plugins/rack_file.rb +3 -0
  89. data/lib/shrine/plugins/rack_response.rb +14 -14
  90. data/lib/shrine/plugins/recache.rb +3 -0
  91. data/lib/shrine/plugins/refresh_metadata.rb +3 -0
  92. data/lib/shrine/plugins/remote_url.rb +3 -0
  93. data/lib/shrine/plugins/remove_attachment.rb +3 -0
  94. data/lib/shrine/plugins/remove_invalid.rb +3 -0
  95. data/lib/shrine/plugins/restore_cached_data.rb +3 -0
  96. data/lib/shrine/plugins/sequel.rb +3 -0
  97. data/lib/shrine/plugins/signature.rb +3 -0
  98. data/lib/shrine/plugins/store_dimensions.rb +4 -1
  99. data/lib/shrine/plugins/tempfile.rb +5 -0
  100. data/lib/shrine/plugins/upload_endpoint.rb +3 -0
  101. data/lib/shrine/plugins/upload_options.rb +3 -0
  102. data/lib/shrine/plugins/validation_helpers.rb +3 -0
  103. data/lib/shrine/plugins/versions.rb +3 -0
  104. data/lib/shrine/uploaded_file.rb +15 -7
  105. data/lib/shrine/version.rb +1 -1
  106. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa6d199c94a3b0f6454d8423cc1ae63e31c78979328b064364abc8119ce9c98b
4
- data.tar.gz: c384cee91997dfa2927938d959362982274adf6befc1ffe1d98be6605f4c4206
3
+ metadata.gz: 6a54ce86ad9f430b7c0896fa83db280316dd3e48a27bff320445b561b966bdcd
4
+ data.tar.gz: 2924f5048e3ff3991d49da834000564612eba1749576c7ea42cf446cb025c7ed
5
5
  SHA512:
6
- metadata.gz: 904c4b61e43102efbc95dbfff02e16af95df2d88fd2ce68a29fa54dff82e512f5801f671eb865527ed892fd34905448871fb120e6133955d20d87f5568c3f5d7
7
- data.tar.gz: e7742141f3693e862a5d13aa0752b59820415ca9bbf62674842730b3962a1452b71c33ea631dd65bec9e0b16aef189387bb545d958edeb80e707d506385e8c3f
6
+ metadata.gz: 7a0e9566b2b6b7a78c2a85019108147bcd071b46cef63fb1cdc848ee1fb1a8cf086afce8bf62d966e88cbeefe35d4437d471c7a7180a8abd34682d47fe62b60b
7
+ data.tar.gz: 013cb42c24c2af94c2aa84344c5ce9e07e6001dfb56a06e2b6f4c4805969c4fa2d45421a455e34d1ec9290607c5ffebddd0114d91871cd99e84b6623cb65527e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## 2.16.0 (2019-02-18)
2
+
3
+ * `derivation_endpoint` – Add `:upload_open_options` for download option for derivation result (@janko)
4
+
5
+ * `derivation_endpoint` – Fix `:upload` option being incompatible with `delete_raw` plugin (@janko)
6
+
7
+ * `derivation_endpoint` – Require input file in `Derivation#upload` to respond to `#path` (@janko)
8
+
9
+ * `derivation_endpoint` – Delete generated derivation result after uploading in `Derivation#upload` (@janko)
10
+
11
+ * `derivation_endpoint` – Fix `Derivation#processed` breaking when derivation result is a `File` object (@janko)
12
+
13
+ * `derivation_endpoint` – Don't close input file on `Derivation#upload` (@janko)
14
+
15
+ * Add `:delete` parameter for skipping delete when `delete_raw` plugin is loaded (@janko)
16
+
17
+ * Don't return `Content-Type` when it couldn't be determined from file extension in `derivation_endpoint` (@janko)
18
+
19
+ * Add `:download_options` option to `download_endpoint` plugin for specifying options for `Storage#open` (@janko)
20
+
21
+ * Don't return `Content-Type` header in `rack_response` when MIME type could not be determined (@janko)
22
+
23
+ * Open the `UploadedFile` object in `#to_rack_response` in `rack_response` plugin (@janko)
24
+
25
+ * Fix `store_dimensions` plugin making second argument in `Shrine#extract_metadata` mandatory (@jrochkind)
26
+
1
27
  ## 2.15.0 (2019-02-08)
2
28
 
3
29
  * Add `derivation_endpoint` plugin for processing uploaded files on-the-fly (@janko)
data/doc/advantages.md CHANGED
@@ -181,6 +181,10 @@ class ImageUploader < Shrine
181
181
  end
182
182
  end
183
183
  ```
184
+ ```rb
185
+ photo.image_url(:large)
186
+ #=> "https://s3.amazonaws.com/path/to/large.jpg"
187
+ ```
184
188
 
185
189
  or generate thumbnails on-demand:
186
190
 
@@ -1,7 +1,7 @@
1
1
  # Active Record
2
2
 
3
- The `activerecord` plugin extends the "attachment" interface with support for
4
- ActiveRecord.
3
+ The [`activerecord`][activerecord] plugin extends the "attachment" interface
4
+ with support for ActiveRecord.
5
5
 
6
6
  ```rb
7
7
  plugin :activerecord
@@ -89,4 +89,5 @@ model errors, you can disable it:
89
89
  plugin :activerecord, validations: false
90
90
  ```
91
91
 
92
+ [activerecord]: /lib/shrine/plugins/activerecord.rb
92
93
  [bug with transaction callbacks]: https://github.com/rails/rails/issues/14493
@@ -1,7 +1,7 @@
1
1
  # Add Metadata
2
2
 
3
- The `add_metadata` plugin provides a convenient method for extracting and
4
- adding custom metadata values.
3
+ The [`add_metadata`][add_metadata] plugin provides a convenient method for
4
+ extracting and adding custom metadata values.
5
5
 
6
6
  ```rb
7
7
  plugin :add_metadata
@@ -91,3 +91,5 @@ add_metadata :bar do |io, context|
91
91
  "bar"
92
92
  end
93
93
  ```
94
+
95
+ [add_metadata]: /lib/shrine/plugins/add_metadata.rb
@@ -1,9 +1,9 @@
1
1
  # Backgrounding
2
2
 
3
- The `backgrounding` plugin enables you to move promoting and deleting of files
4
- from record's lifecycle into background jobs. This is especially useful if
5
- you're doing processing and/or you're storing files on an external storage
6
- service.
3
+ The [`backgrounding`][backgrounding] plugin enables you to move promoting and
4
+ deleting of files from record's lifecycle into background jobs. This is
5
+ especially useful if you're doing processing and/or you're storing files on an
6
+ external storage service.
7
7
 
8
8
  The plugin provides `Attacher.promote` and `Attacher.delete` methods, which
9
9
  allow you to hook up to promoting and deleting and spawn background jobs, by
@@ -146,3 +146,5 @@ class SomethingJob
146
146
  end
147
147
  end
148
148
  ```
149
+
150
+ [backgrounding]: /lib/shrine/plugins/backgrounding.rb
@@ -1,7 +1,7 @@
1
1
  # Backup
2
2
 
3
- The `backup` plugin allows you to automatically back up stored files to an
4
- additional storage.
3
+ The [`backup`][backup] plugin allows you to automatically back up stored files
4
+ to an additional storage.
5
5
 
6
6
  ```rb
7
7
  storages[:backup_store] = Shrine::Storage::S3.new(options)
@@ -27,3 +27,5 @@ Note that when adding this plugin with already existing stored files, Shrine
27
27
  won't know whether a stored file is backed up or not, so attempting to delete
28
28
  the backup could result in an error. To avoid that you can set `delete: false`
29
29
  until you manually back up the existing stored files.
30
+
31
+ [backup]: /lib/shrine/plugins/backup.rb
@@ -1,8 +1,8 @@
1
1
  # Cached Attachment Data
2
2
 
3
- The `cached_attachment_data` plugin adds the ability to retain the cached file
4
- across form redisplays, which means the file doesn't have to be reuploaded in
5
- case of validation errors.
3
+ The [`cached_attachment_data`][cached_attachment_data] plugin adds the ability
4
+ to retain the cached file across form redisplays, which means the file doesn't
5
+ have to be reuploaded in case of validation errors.
6
6
 
7
7
  ```rb
8
8
  plugin :cached_attachment_data
@@ -21,3 +21,5 @@ This method delegates to `Attacher#read_cached`:
21
21
  ```rb
22
22
  attacher.read_cached #=> '{"id":"38k25.jpg","storage":"cache","metadata":{...}}'
23
23
  ```
24
+
25
+ [cached_attachment_data]: /lib/shrine/plugins/cached_attachment_data.rb
data/doc/plugins/copy.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Copy
2
2
 
3
- The `copy` plugin allows copying attachment from one record to another.
3
+ The [`copy`][copy] plugin allows copying attachment from one record to another.
4
4
 
5
5
  ```rb
6
6
  plugin :copy
@@ -20,3 +20,5 @@ duplicated_photo = photo.dup
20
20
  duplicated_photo.image #=> #<Shrine::UploadedFile>
21
21
  duplicated_photo.image != photo.image
22
22
  ```
23
+
24
+ [copy]: /lib/shrine/plugins/copy.rb
@@ -1,7 +1,7 @@
1
1
  # Data URI
2
2
 
3
- The `data_uri` plugin enables you to upload files as [data URIs]. This plugin
4
- is useful for example when using [HTML5 Canvas].
3
+ The [`data_uri`][data_uri] plugin enables you to upload files as [data URIs].
4
+ This plugin is useful for example when using [HTML5 Canvas].
5
5
 
6
6
  ```rb
7
7
  plugin :data_uri
@@ -88,5 +88,6 @@ uploaded_file.data_uri #=> "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA"
88
88
  uploaded_file.base64 #=> "iVBORw0KGgoAAAANSUhEUgAAAAUA"
89
89
  ```
90
90
 
91
+ [data_uri]: /lib/shrine/plugins/data_uri.rb
91
92
  [data URIs]: https://tools.ietf.org/html/rfc2397
92
93
  [HTML5 Canvas]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API
@@ -1,7 +1,8 @@
1
1
  # Default Storage
2
2
 
3
- The `default_storage` plugin enables you to change which storages are going to
4
- be used for this uploader's attacher (the default is `:cache` and `:store`).
3
+ The [`default_storage`][default_storage] plugin enables you to change which
4
+ storages are going to be used for this uploader's attacher (the default is
5
+ `:cache` and `:store`).
5
6
 
6
7
  ```rb
7
8
  plugin :default_storage, cache: :special_cache, store: :special_store
@@ -14,3 +15,5 @@ and the name of the attachment. This is useful if you're using the
14
15
  ```rb
15
16
  plugin :default_storage, store: ->(record, name) { :"store_#{record.username}" }
16
17
  ```
18
+
19
+ [default_storage]: /lib/shrine/plugins/default_storage.rb
@@ -1,7 +1,7 @@
1
1
  # Default URL
2
2
 
3
- The `default_url` plugin allows setting the URL which will be returned when the
4
- attachment is missing.
3
+ The [`default_url`][default_url] plugin allows setting the URL which will be
4
+ returned when the attachment is missing.
5
5
 
6
6
  ```rb
7
7
  plugin :default_url
@@ -31,3 +31,5 @@ Attacher.default_url do |options|
31
31
  record #=> #<User>
32
32
  end
33
33
  ```
34
+
35
+ [default_url]: /lib/shrine/plugins/default_url.rb
@@ -1,7 +1,8 @@
1
1
  # Default URL Options
2
2
 
3
- The `default_url_options` plugin allows you to specify URL options that will be
4
- applied by default for uploaded files of specified storages.
3
+ The [`default_url_options`][default_url_options] plugin allows you to specify
4
+ URL options that will be applied by default for uploaded files of specified
5
+ storages.
5
6
 
6
7
  ```rb
7
8
  plugin :default_url_options, store: { download: true }
@@ -20,3 +21,5 @@ end
20
21
  In both cases the default options are merged with options passed to
21
22
  `UploadedFile#url`, and the latter will always have precedence over default
22
23
  options.
24
+
25
+ [default_url_options]: /lib/shrine/plugins/default_url_options.rb
@@ -1,10 +1,12 @@
1
1
  # Delete Promoted
2
2
 
3
- The `delete_promoted` plugin deletes files that have been promoted, after the
4
- record is saved. This means that cached files handled by the attacher will
5
- automatically get deleted once they're uploaded to store. This also applies to
6
- any other uploaded file passed to `Attacher#promote`.
3
+ The [`delete_promoted`][delete_promoted] plugin deletes files that have been
4
+ promoted, after the record is saved. This means that cached files handled by
5
+ the attacher will automatically get deleted once they're uploaded to store.
6
+ This also applies to any other uploaded file passed to `Attacher#promote`.
7
7
 
8
8
  ```rb
9
9
  plugin :delete_promoted
10
10
  ```
11
+
12
+ [delete_promoted]: /lib/shrine/plugins/delete_promoted.rb
@@ -1,8 +1,8 @@
1
1
  # Delete Raw
2
2
 
3
- The `delete_raw` plugin will automatically delete raw files that have been
4
- uploaded. This is especially useful when doing processing, to ensure that
5
- temporary files have been deleted after upload.
3
+ The [`delete_raw`][delete_raw] plugin will automatically delete raw files that
4
+ have been uploaded. This is especially useful when doing processing, to ensure
5
+ that temporary files have been deleted after upload.
6
6
 
7
7
  ```rb
8
8
  plugin :delete_raw
@@ -14,3 +14,12 @@ this only to files uploaded to certain storages:
14
14
  ```rb
15
15
  plugin :delete_raw, storages: [:store]
16
16
  ```
17
+
18
+ If you want to skip deletion for a certain upload, you can pass `delete: false`
19
+ to the uploader:
20
+
21
+ ```rb
22
+ uploader.upload(file, delete: false)
23
+ ```
24
+
25
+ [delete_raw]: /lib/shrine/plugins/delete_raw.rb
@@ -1,8 +1,9 @@
1
1
  # Derivation Endpoint
2
2
 
3
- The `derivation_endpoint` plugin provides a Rack app for dynamically processing
4
- uploaded files on request. This allows you to create URLs to files that might
5
- not have been generated yet, and have the endpoint process them on-the-fly.
3
+ The [`derivation_endpoint`][derivation_endpoint] plugin provides a Rack app for
4
+ dynamically processing uploaded files on request. This allows you to create
5
+ URLs to files that might not have been generated yet, and have the endpoint
6
+ process them on-the-fly.
6
7
 
7
8
  ## Quick start
8
9
 
@@ -349,9 +350,9 @@ uploaded_file.derivation_url(:webp, type: "image/webp")
349
350
  ### Content Disposition
350
351
 
351
352
  The derivation response includes the [`Content-Disposition`] header. By default
352
- the disposition is set to `inline`, while the download filename is generated
353
- from derivation name, arguments and source file id. These values can be changed
354
- with the `:disposition` and `:filename` options:
353
+ the disposition is set to `inline`, with download filename generated from
354
+ derivation name, arguments and source file id. These values can be changed with
355
+ the `:disposition` and `:filename` options:
355
356
 
356
357
  ```rb
357
358
  plugin :derivation_endpoint,
@@ -434,6 +435,14 @@ plugin :derivation_endpoint, upload: true,
434
435
  upload_options: { acl: "public-read" }
435
436
  ```
436
437
 
438
+ Additional storage-specific download options for the uploaded derivation result
439
+ can be passed via `:upload_open_options`:
440
+
441
+ ```rb
442
+ plugin :derivation_endpoint, upload: true,
443
+ upload_open_options: { response_content_encoding: "gzip" }
444
+ ```
445
+
437
446
  ### Redirecting
438
447
 
439
448
  You can configure the endpoint to redirect to the uploaded derivative on the
@@ -736,11 +745,13 @@ derivation.option(:upload_location)
736
745
  | `:upload` | Whether the generated derivatives will be cached on the storage | `false` |
737
746
  | `:upload_location` | Location to which the derivatives will be uploaded on the storage | `<source id>/<name>-<args>` |
738
747
  | `:upload_options` | Additional options to be passed when uploading derivatives | `{}` |
748
+ | `:upload_open_options` | Additional options to be passed when downloading the uploaded derivative | `{}` |
739
749
  | `:upload_redirect` | Whether the derivation response should redirect to the uploaded derivative | `false` |
740
750
  | `:upload_redirect_url_options` | Additional options to be passed when generating the URL for the uploaded derivative | `{}` |
741
751
  | `:upload_storage` | Storage to which the derivations will be uploaded | same storage as the source file |
742
752
  | `:version` | Version number to append to the URL for cache busting | `nil` |
743
753
 
754
+ [derivation_endpoint]: /lib/shrine/plugins/derivation_endpoint.rb
744
755
  [ImageProcessing]: https://github.com/janko/image_processing
745
756
  [`Content-Type`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
746
757
  [`Content-Disposition`]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition
@@ -1,7 +1,7 @@
1
1
  # Determine MIME Type
2
2
 
3
- The `determine_mime_type` plugin allows you to determine and store the actual
4
- MIME type of the file analyzed from file content.
3
+ The [`determine_mime_type`][determine_mime_type] plugin allows you to determine
4
+ and store the actual MIME type of the file analyzed from file content.
5
5
 
6
6
  ```rb
7
7
  plugin :determine_mime_type
@@ -54,6 +54,7 @@ Shrine.mime_type_analyzers[:file].call(io) # calls a built-in analyzer
54
54
  #=> "image/jpeg"
55
55
  ```
56
56
 
57
+ [determine_mime_type]: /lib/shrine/plugins/determine_mime_type.rb
57
58
  [file]: http://linux.die.net/man/1/file
58
59
  [Windows equivalent]: http://gnuwin32.sourceforge.net/packages/file.htm
59
60
  [ruby-filemagic]: https://github.com/blackwinter/ruby-filemagic
@@ -3,8 +3,9 @@
3
3
  *[OBSOLETE] This plugin is obsolete, you should use `upload_endpoint` or
4
4
  `presign_endpoint` plugins instead.*
5
5
 
6
- The `direct_upload` plugin provides a Rack endpoint which can be used for
7
- uploading individual files asynchronously. It requires the [Roda] gem.
6
+ The [`direct_upload`][direct_upload] plugin provides a Rack endpoint which can
7
+ be used for uploading individual files asynchronously. It requires the [Roda]
8
+ gem.
8
9
 
9
10
  ```rb
10
11
  plugin :direct_upload
@@ -164,6 +165,7 @@ Shrine::UploadEndpoint.use ShrineUploadMiddleware
164
165
  Upon subclassing uploader the upload endpoint is also subclassed. You can also
165
166
  call the plugin again in an uploader subclass to change its configuration.
166
167
 
168
+ [direct_upload]: /lib/shrine/plugins/direct_upload.rb
167
169
  [Roda]: https://github.com/jeremyevans/roda
168
170
  [Uppy]: https://uppy.io
169
171
  [Roda request]: http://roda.jeremyevans.net/rdoc/classes/Roda/RodaPlugins/Base/RequestMethods.html
@@ -1,9 +1,9 @@
1
1
  # Download Endpoint
2
2
 
3
- The `download_endpoint` plugin provides a Rack app for downloading uploaded
4
- files from specified storages. This can be useful when files from your storage
5
- isn't accessible over URL (e.g. database storages) or if you want to
6
- authenticate your downloads. It requires the [Roda] gem.
3
+ The [`download_endpoint`][download_endpoint] plugin provides a Rack app for
4
+ downloading uploaded files from specified storages. This can be useful when
5
+ files from your storage isn't accessible over URL (e.g. database storages) or
6
+ if you want to authenticate your downloads. It requires the [Roda] gem.
7
7
 
8
8
  ```rb
9
9
  # Gemfile
@@ -59,6 +59,31 @@ uploaded_file.download_url(host: "http://example.com")
59
59
  #=> "http//example.com/attachments/eyJpZCI6ImFkdzlyeTM..."
60
60
  ```
61
61
 
62
+ ## Download options
63
+
64
+ If you want to pass additional options to `Storage#open`, you can do so via
65
+ `:download_options`:
66
+
67
+ ```rb
68
+ plugin :download_endpoint, download_options: {
69
+ sse_customer_algorithm: "AES256",
70
+ sse_customer_key: "secret_key",
71
+ sse_customer_key_md5: "secret_key_md5",
72
+ }
73
+ ```
74
+
75
+ You can also specify a proc to generate download options dynamically:
76
+
77
+ ```rb
78
+ plugin :download_enpdoint, download_options: -> (uploaded_file, request) {
79
+ {
80
+ sse_customer_algorithm: "AES256",
81
+ sse_customer_key: "secret_key",
82
+ sse_customer_key_md5: "secret_key_md5",
83
+ }
84
+ }
85
+ ```
86
+
62
87
  ## Performance considerations
63
88
 
64
89
  Streaming files through the app might impact the request throughput, depending
@@ -69,9 +94,13 @@ Alternatively, you can have the endpoint redirect to the direct file URL:
69
94
 
70
95
  ```rb
71
96
  plugin :download_endpoint, redirect: true
72
- # or
97
+ ```
98
+
99
+ You can also specify a proc to generate your own redirect URL:
100
+
101
+ ```rb
73
102
  plugin :download_endpoint, redirect: -> (uploaded_file, request) do
74
- # return URL which the request will redirect to
103
+ uploaded_file.url(public: true)
75
104
  end
76
105
  ```
77
106
 
@@ -80,4 +109,15 @@ end
80
109
  If you want to have more control on download requests, you can use the
81
110
  `rack_response` plugin which this plugin uses internally.
82
111
 
112
+ ## Plugin options
113
+
114
+ | Name | Description | Default |
115
+ | :-------- | :---------- | :------ |
116
+ | `:disposition` | Whether browser should render the file `inline` or download it as an `attachment` | `inline` |
117
+ | `:download_options` | Hash of storage-specific options passed to `Storage#open` | `{}` |
118
+ | `:host` | URL host that will be added to download URLs | `nil` |
119
+ | `:prefix` | Path prefix prepended to download URLs | `nil` |
120
+ | `:redirect` | Whether to redirect to uploaded files on the storage | `false` |
121
+
122
+ [download_endpoint]: /lib/shrine/plugins/download_endpoint.rb
83
123
  [Roda]: https://github.com/jeremyevans/roda
@@ -1,7 +1,8 @@
1
1
  # Dynamic Storage
2
2
 
3
- The `dynamic_storage` plugin allows you to register a storage using a regex,
4
- and evaluate the storage class dynamically depending on the regex.
3
+ The [`dynamic_storage`][dynamic_storage] plugin allows you to register a
4
+ storage using a regex, and evaluate the storage class dynamically depending on
5
+ the regex.
5
6
 
6
7
  Example:
7
8
 
@@ -18,3 +19,5 @@ name suffix. For example, `:store_foo` will use S3 storage which saves files to
18
19
  the bucket "foo". The block is yielded an instance of `MatchData`.
19
20
 
20
21
  This can be useful in combination with the `default_storage` plugin.
22
+
23
+ [dynamic_storage]: /lib/shrine/plugins/dynamic_storage.rb