shrine 2.19.4 → 3.0.0.alpha

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +299 -11
  3. data/README.md +9 -3
  4. data/doc/advantages.md +1 -1
  5. data/doc/carrierwave.md +4 -4
  6. data/doc/creating_persistence_plugins.md +172 -0
  7. data/doc/creating_plugins.md +1 -1
  8. data/doc/creating_storages.md +3 -1
  9. data/doc/design.md +2 -2
  10. data/doc/direct_s3.md +0 -22
  11. data/doc/paperclip.md +3 -3
  12. data/doc/plugins/activerecord.md +211 -42
  13. data/doc/plugins/atomic_helpers.md +153 -0
  14. data/doc/plugins/column.md +90 -0
  15. data/doc/plugins/derivation_endpoint.md +54 -62
  16. data/doc/plugins/derivatives.md +752 -0
  17. data/doc/plugins/entity.md +204 -0
  18. data/doc/plugins/infer_extension.md +8 -8
  19. data/doc/plugins/instrumentation.md +33 -13
  20. data/doc/plugins/keep_files.md +5 -15
  21. data/doc/plugins/model.md +157 -0
  22. data/doc/plugins/presign_endpoint.md +2 -1
  23. data/doc/plugins/refresh_metadata.md +44 -7
  24. data/doc/plugins/sequel.md +190 -33
  25. data/doc/plugins/{default_url_options.md → url_options.md} +5 -5
  26. data/doc/processing.md +1 -1
  27. data/doc/release_notes/1.1.0.md +2 -2
  28. data/doc/release_notes/2.15.0.md +1 -1
  29. data/doc/storage/s3.md +2 -2
  30. data/doc/testing.md +1 -1
  31. data/lib/shrine.rb +72 -138
  32. data/lib/shrine/attacher.rb +272 -176
  33. data/lib/shrine/attachment.rb +2 -42
  34. data/lib/shrine/plugins/activerecord.rb +103 -26
  35. data/lib/shrine/plugins/add_metadata.rb +9 -10
  36. data/lib/shrine/plugins/atomic_helpers.rb +111 -0
  37. data/lib/shrine/plugins/attacher_options.rb +55 -0
  38. data/lib/shrine/plugins/backgrounding.rb +147 -115
  39. data/lib/shrine/plugins/cached_attachment_data.rb +6 -9
  40. data/lib/shrine/plugins/column.rb +104 -0
  41. data/lib/shrine/plugins/data_uri.rb +35 -38
  42. data/lib/shrine/plugins/default_storage.rb +18 -12
  43. data/lib/shrine/plugins/default_url.rb +11 -21
  44. data/lib/shrine/plugins/default_url_options.rb +3 -30
  45. data/lib/shrine/plugins/delete_raw.rb +9 -13
  46. data/lib/shrine/plugins/derivation_endpoint.rb +75 -114
  47. data/lib/shrine/plugins/derivatives.rb +576 -0
  48. data/lib/shrine/plugins/determine_mime_type.rb +3 -15
  49. data/lib/shrine/plugins/download_endpoint.rb +83 -131
  50. data/lib/shrine/plugins/dynamic_storage.rb +4 -8
  51. data/lib/shrine/plugins/entity.rb +128 -0
  52. data/lib/shrine/plugins/form_assign.rb +107 -0
  53. data/lib/shrine/plugins/included.rb +4 -3
  54. data/lib/shrine/plugins/infer_extension.rb +10 -17
  55. data/lib/shrine/plugins/instrumentation.rb +45 -25
  56. data/lib/shrine/plugins/keep_files.rb +2 -12
  57. data/lib/shrine/plugins/metadata_attributes.rb +15 -14
  58. data/lib/shrine/plugins/model.rb +137 -0
  59. data/lib/shrine/plugins/module_include.rb +2 -0
  60. data/lib/shrine/plugins/presign_endpoint.rb +1 -15
  61. data/lib/shrine/plugins/pretty_location.rb +5 -5
  62. data/lib/shrine/plugins/processing.rb +21 -6
  63. data/lib/shrine/plugins/rack_file.rb +1 -39
  64. data/lib/shrine/plugins/rack_response.rb +14 -7
  65. data/lib/shrine/plugins/recache.rb +5 -2
  66. data/lib/shrine/plugins/refresh_metadata.rb +12 -8
  67. data/lib/shrine/plugins/remote_url.rb +44 -53
  68. data/lib/shrine/plugins/remove_attachment.rb +7 -2
  69. data/lib/shrine/plugins/remove_invalid.rb +8 -4
  70. data/lib/shrine/plugins/restore_cached_data.rb +12 -4
  71. data/lib/shrine/plugins/sequel.rb +115 -27
  72. data/lib/shrine/plugins/signature.rb +2 -7
  73. data/lib/shrine/plugins/store_dimensions.rb +13 -27
  74. data/lib/shrine/plugins/upload_endpoint.rb +14 -15
  75. data/lib/shrine/plugins/upload_options.rb +9 -8
  76. data/lib/shrine/plugins/url_options.rb +33 -0
  77. data/lib/shrine/plugins/validation.rb +87 -0
  78. data/lib/shrine/plugins/validation_helpers.rb +33 -54
  79. data/lib/shrine/plugins/versions.rb +106 -84
  80. data/lib/shrine/storage/file_system.rb +32 -57
  81. data/lib/shrine/storage/linter.rb +9 -1
  82. data/lib/shrine/storage/memory.rb +42 -0
  83. data/lib/shrine/storage/s3.rb +38 -146
  84. data/lib/shrine/uploaded_file.rb +22 -29
  85. data/lib/shrine/version.rb +4 -4
  86. data/shrine.gemspec +2 -3
  87. metadata +27 -54
  88. data/doc/plugins/backup.md +0 -31
  89. data/doc/plugins/copy.md +0 -24
  90. data/doc/plugins/delete_promoted.md +0 -12
  91. data/doc/plugins/direct_upload.md +0 -172
  92. data/doc/plugins/hooks.md +0 -58
  93. data/doc/plugins/logging.md +0 -42
  94. data/doc/plugins/migration_helpers.md +0 -60
  95. data/doc/plugins/moving.md +0 -19
  96. data/doc/plugins/multi_delete.md +0 -20
  97. data/doc/plugins/parallelize.md +0 -16
  98. data/doc/plugins/parsed_json.md +0 -23
  99. data/lib/shrine/plugins/background_helpers.rb +0 -5
  100. data/lib/shrine/plugins/backup.rb +0 -90
  101. data/lib/shrine/plugins/copy.rb +0 -50
  102. data/lib/shrine/plugins/delete_promoted.rb +0 -20
  103. data/lib/shrine/plugins/direct_upload.rb +0 -217
  104. data/lib/shrine/plugins/hooks.rb +0 -90
  105. data/lib/shrine/plugins/logging.rb +0 -142
  106. data/lib/shrine/plugins/migration_helpers.rb +0 -70
  107. data/lib/shrine/plugins/moving.rb +0 -57
  108. data/lib/shrine/plugins/multi_delete.rb +0 -32
  109. data/lib/shrine/plugins/parallelize.rb +0 -78
  110. data/lib/shrine/plugins/parsed_json.rb +0 -29
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.19.4
4
+ version: 3.0.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-16 00:00:00.000000000 Z
11
+ date: 2019-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.1'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '6'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ">="
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '4.1'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '6'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: content_disposition
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -72,20 +66,6 @@ dependencies:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
68
  version: '5.8'
75
- - !ruby/object:Gem::Dependency
76
- name: minitest-hooks
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
79
- - - "~>"
80
- - !ruby/object:Gem::Version
81
- version: '1.3'
82
- type: :development
83
- prerelease: false
84
- version_requirements: !ruby/object:Gem::Requirement
85
- requirements:
86
- - - "~>"
87
- - !ruby/object:Gem::Version
88
- version: '1.3'
89
69
  - !ruby/object:Gem::Dependency
90
70
  name: mocha
91
71
  requirement: !ruby/object:Gem::Requirement
@@ -101,19 +81,19 @@ dependencies:
101
81
  - !ruby/object:Gem::Version
102
82
  version: '1.4'
103
83
  - !ruby/object:Gem::Dependency
104
- name: shrine-memory
84
+ name: dry-initializer
105
85
  requirement: !ruby/object:Gem::Requirement
106
86
  requirements:
107
87
  - - ">="
108
88
  - !ruby/object:Gem::Version
109
- version: 0.2.2
89
+ version: '0'
110
90
  type: :development
111
91
  prerelease: false
112
92
  version_requirements: !ruby/object:Gem::Requirement
113
93
  requirements:
114
94
  - - ">="
115
95
  - !ruby/object:Gem::Version
116
- version: 0.2.2
96
+ version: '0'
117
97
  - !ruby/object:Gem::Dependency
118
98
  name: rack
119
99
  requirement: !ruby/object:Gem::Requirement
@@ -388,6 +368,7 @@ files:
388
368
  - doc/attacher.md
389
369
  - doc/carrierwave.md
390
370
  - doc/changing_location.md
371
+ - doc/creating_persistence_plugins.md
391
372
  - doc/creating_plugins.md
392
373
  - doc/creating_storages.md
393
374
  - doc/design.md
@@ -398,34 +379,27 @@ files:
398
379
  - doc/paperclip.md
399
380
  - doc/plugins/activerecord.md
400
381
  - doc/plugins/add_metadata.md
382
+ - doc/plugins/atomic_helpers.md
401
383
  - doc/plugins/backgrounding.md
402
- - doc/plugins/backup.md
403
384
  - doc/plugins/cached_attachment_data.md
404
- - doc/plugins/copy.md
385
+ - doc/plugins/column.md
405
386
  - doc/plugins/data_uri.md
406
387
  - doc/plugins/default_storage.md
407
388
  - doc/plugins/default_url.md
408
- - doc/plugins/default_url_options.md
409
- - doc/plugins/delete_promoted.md
410
389
  - doc/plugins/delete_raw.md
411
390
  - doc/plugins/derivation_endpoint.md
391
+ - doc/plugins/derivatives.md
412
392
  - doc/plugins/determine_mime_type.md
413
- - doc/plugins/direct_upload.md
414
393
  - doc/plugins/download_endpoint.md
415
394
  - doc/plugins/dynamic_storage.md
416
- - doc/plugins/hooks.md
395
+ - doc/plugins/entity.md
417
396
  - doc/plugins/included.md
418
397
  - doc/plugins/infer_extension.md
419
398
  - doc/plugins/instrumentation.md
420
399
  - doc/plugins/keep_files.md
421
- - doc/plugins/logging.md
422
400
  - doc/plugins/metadata_attributes.md
423
- - doc/plugins/migration_helpers.md
401
+ - doc/plugins/model.md
424
402
  - doc/plugins/module_include.md
425
- - doc/plugins/moving.md
426
- - doc/plugins/multi_delete.md
427
- - doc/plugins/parallelize.md
428
- - doc/plugins/parsed_json.md
429
403
  - doc/plugins/presign_endpoint.md
430
404
  - doc/plugins/pretty_location.md
431
405
  - doc/plugins/processing.md
@@ -443,6 +417,7 @@ files:
443
417
  - doc/plugins/tempfile.md
444
418
  - doc/plugins/upload_endpoint.md
445
419
  - doc/plugins/upload_options.md
420
+ - doc/plugins/url_options.md
446
421
  - doc/plugins/validation_helpers.md
447
422
  - doc/plugins/versions.md
448
423
  - doc/processing.md
@@ -494,35 +469,30 @@ files:
494
469
  - lib/shrine/plugins/_urlsafe_serialization.rb
495
470
  - lib/shrine/plugins/activerecord.rb
496
471
  - lib/shrine/plugins/add_metadata.rb
497
- - lib/shrine/plugins/background_helpers.rb
472
+ - lib/shrine/plugins/atomic_helpers.rb
473
+ - lib/shrine/plugins/attacher_options.rb
498
474
  - lib/shrine/plugins/backgrounding.rb
499
- - lib/shrine/plugins/backup.rb
500
475
  - lib/shrine/plugins/cached_attachment_data.rb
501
- - lib/shrine/plugins/copy.rb
476
+ - lib/shrine/plugins/column.rb
502
477
  - lib/shrine/plugins/data_uri.rb
503
478
  - lib/shrine/plugins/default_storage.rb
504
479
  - lib/shrine/plugins/default_url.rb
505
480
  - lib/shrine/plugins/default_url_options.rb
506
- - lib/shrine/plugins/delete_promoted.rb
507
481
  - lib/shrine/plugins/delete_raw.rb
508
482
  - lib/shrine/plugins/derivation_endpoint.rb
483
+ - lib/shrine/plugins/derivatives.rb
509
484
  - lib/shrine/plugins/determine_mime_type.rb
510
- - lib/shrine/plugins/direct_upload.rb
511
485
  - lib/shrine/plugins/download_endpoint.rb
512
486
  - lib/shrine/plugins/dynamic_storage.rb
513
- - lib/shrine/plugins/hooks.rb
487
+ - lib/shrine/plugins/entity.rb
488
+ - lib/shrine/plugins/form_assign.rb
514
489
  - lib/shrine/plugins/included.rb
515
490
  - lib/shrine/plugins/infer_extension.rb
516
491
  - lib/shrine/plugins/instrumentation.rb
517
492
  - lib/shrine/plugins/keep_files.rb
518
- - lib/shrine/plugins/logging.rb
519
493
  - lib/shrine/plugins/metadata_attributes.rb
520
- - lib/shrine/plugins/migration_helpers.rb
494
+ - lib/shrine/plugins/model.rb
521
495
  - lib/shrine/plugins/module_include.rb
522
- - lib/shrine/plugins/moving.rb
523
- - lib/shrine/plugins/multi_delete.rb
524
- - lib/shrine/plugins/parallelize.rb
525
- - lib/shrine/plugins/parsed_json.rb
526
496
  - lib/shrine/plugins/presign_endpoint.rb
527
497
  - lib/shrine/plugins/pretty_location.rb
528
498
  - lib/shrine/plugins/processing.rb
@@ -540,10 +510,13 @@ files:
540
510
  - lib/shrine/plugins/tempfile.rb
541
511
  - lib/shrine/plugins/upload_endpoint.rb
542
512
  - lib/shrine/plugins/upload_options.rb
513
+ - lib/shrine/plugins/url_options.rb
514
+ - lib/shrine/plugins/validation.rb
543
515
  - lib/shrine/plugins/validation_helpers.rb
544
516
  - lib/shrine/plugins/versions.rb
545
517
  - lib/shrine/storage/file_system.rb
546
518
  - lib/shrine/storage/linter.rb
519
+ - lib/shrine/storage/memory.rb
547
520
  - lib/shrine/storage/s3.rb
548
521
  - lib/shrine/uploaded_file.rb
549
522
  - lib/shrine/version.rb
@@ -568,11 +541,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
568
541
  version: '2.3'
569
542
  required_rubygems_version: !ruby/object:Gem::Requirement
570
543
  requirements:
571
- - - ">="
544
+ - - ">"
572
545
  - !ruby/object:Gem::Version
573
- version: '0'
546
+ version: 1.3.1
574
547
  requirements: []
575
- rubygems_version: 3.1.2
548
+ rubygems_version: 3.0.3
576
549
  signing_key:
577
550
  specification_version: 4
578
551
  summary: Toolkit for file attachments in Ruby applications
@@ -1,31 +0,0 @@
1
- # Backup
2
-
3
- The [`backup`][backup] plugin allows you to automatically back up stored files
4
- to an additional storage.
5
-
6
- ```rb
7
- storages[:backup_store] = Shrine::Storage::S3.new(options)
8
- plugin :backup, storage: :backup_store
9
- ```
10
-
11
- After a file is stored, it will be reuploaded from store to the provided backup
12
- storage.
13
-
14
- ```rb
15
- user.update(avatar: file) # uploaded both to :store and :backup_store
16
- ```
17
-
18
- By default whenever stored files are deleted backed up files are deleted as
19
- well, but you can keep files on the "backup" storage by passing `delete:
20
- false`:
21
-
22
- ```rb
23
- plugin :backup, storage: :backup_store, delete: false
24
- ```
25
-
26
- Note that when adding this plugin with already existing stored files, Shrine
27
- won't know whether a stored file is backed up or not, so attempting to delete
28
- the backup could result in an error. To avoid that you can set `delete: false`
29
- until you manually back up the existing stored files.
30
-
31
- [backup]: /lib/shrine/plugins/backup.rb
data/doc/plugins/copy.md DELETED
@@ -1,24 +0,0 @@
1
- # Copy
2
-
3
- The [`copy`][copy] plugin allows copying attachment from one record to another.
4
-
5
- ```rb
6
- plugin :copy
7
- ```
8
-
9
- It adds a `Attacher#copy` method, which accepts another attacher, and copies
10
- the attachment from it:
11
-
12
- ```rb
13
- photo.image_attacher.copy(other_photo.image_attacher)
14
- ```
15
-
16
- This method will automatically be called when the record is duplicated:
17
-
18
- ```rb
19
- duplicated_photo = photo.dup
20
- duplicated_photo.image #=> #<Shrine::UploadedFile>
21
- duplicated_photo.image != photo.image
22
- ```
23
-
24
- [copy]: /lib/shrine/plugins/copy.rb
@@ -1,12 +0,0 @@
1
- # Delete Promoted
2
-
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
-
8
- ```rb
9
- plugin :delete_promoted
10
- ```
11
-
12
- [delete_promoted]: /lib/shrine/plugins/delete_promoted.rb
@@ -1,172 +0,0 @@
1
- # Direct Upload
2
-
3
- *[OBSOLETE] This plugin is obsolete, you should use `upload_endpoint` or
4
- `presign_endpoint` plugins instead.*
5
-
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.
9
-
10
- ```rb
11
- plugin :direct_upload
12
- ```
13
-
14
- The Roda endpoint provides two routes:
15
-
16
- * `POST /:storage/upload`
17
- * `GET /:storage/presign`
18
-
19
- This first route is for doing direct uploads to your app, the received file
20
- will be uploaded the underlying storage. The second route is for doing direct
21
- uploads to a 3rd-party service, it will return the URL where the file can be
22
- uploaded to, along with the necessary request parameters.
23
-
24
- This is how you can mount the endpoint in a Rails application:
25
-
26
- ```rb
27
- Rails.application.routes.draw do
28
- mount ImageUploader::UploadEndpoint => "/images"
29
- end
30
- ```
31
-
32
- Now your application will get `POST /images/cache/upload` and `GET
33
- /images/cache/presign` routes. On the client side it is recommended to use
34
- [Uppy] for uploading files to the app or directly to the 3rd-party service.
35
-
36
- ## Uploads
37
-
38
- The upload route accepts a "file" query parameter, and returns the uploaded
39
- file in JSON format:
40
-
41
- ```rb
42
- # POST /images/cache/upload
43
- {
44
- "id": "43kewit94.jpg",
45
- "storage": "cache",
46
- "metadata": {
47
- "size": 384393,
48
- "filename": "nature.jpg",
49
- "mime_type": "image/jpeg"
50
- }
51
- }
52
- ```
53
-
54
- Once you've uploaded the file, you can assign the result to the hidden
55
- attachment field in the form, or immediately send it to the server.
56
-
57
- Note that the endpoint uploads the file standalone, without any knowledge of
58
- the record, so `context[:record]` and `context[:name]` will be nil.
59
-
60
- ### Limiting filesize
61
-
62
- It's good idea to limit the maximum filesize of uploaded files, if you set the
63
- `:max_size` option, files which are too big will get automatically deleted and
64
- 413 status will be returned:
65
-
66
- ```rb
67
- plugin :direct_upload, max_size: 5*1024*1024 # 5 MB
68
- ```
69
-
70
- Note that this option doesn't affect presigned uploads, there you can apply
71
- filesize limit when generating a presign. The filesize constraint here is for
72
- security purposes, you should still perform file validations on attaching.
73
-
74
- ## Presigns
75
-
76
- The presign route returns the URL to the 3rd-party service to which you can
77
- upload the file, along with the necessary query parameters.
78
-
79
- ```rb
80
- # GET /images/cache/presign
81
- {
82
- "url" => "https://my-bucket.s3-eu-west-1.amazonaws.com",
83
- "fields" => {
84
- "key" => "b7d575850ba61b44c8a9ff889dfdb14d88cdc25f8dd121004c8",
85
- "policy" => "eyJleHBpcmF0aW9uIjoiMjAxNS0QwMToxMToyOVoiLCJjb2...",
86
- "x-amz-credential" => "AKIAIJF55TMZYT6Q/20151024/eu-west-1/s3/aws4_request",
87
- "x-amz-algorithm" => "AWS4-HMAC-SHA256",
88
- "x-amz-date" => "20151024T001129Z",
89
- "x-amz-signature" => "c1eb634f83f96b69bd675f535b3ff15ae184b102fcba51e4db5f4959b4ae26f4"
90
- }
91
- }
92
- ```
93
-
94
- If you want that the generated location includes a file extension, you can
95
- specify the `extension` query parameter: `GET
96
- /:storage/presign?extension=.png`.
97
-
98
- You can also completely change how the key is generated, with
99
- `:presign_location`:
100
-
101
- ```rb
102
- plugin :direct_upload, presign_location: -> (request) { "${filename}" }
103
- ```
104
-
105
- This presign route internally calls `#presign` on the storage, and many
106
- storages accept additional service-specific options. You can generate these
107
- additional options per-request through `:presign_options`:
108
-
109
- ```rb
110
- plugin :direct_upload, presign_options: { acl: "public-read" }
111
-
112
- plugin :direct_upload, presign_options: ->(request) do
113
- filename = request.params["filename"]
114
- content_type = Rack::Mime.mime_type(File.extname(filename))
115
-
116
- {
117
- content_length_range: 0..(10*1024*1024), # limit filesize to 10MB
118
- content_disposition: "attachment; filename=\"#{filename}\"", # download with original filename
119
- content_type: content_type, # set correct content type
120
- }
121
- end
122
- ```
123
-
124
- Both `:presign_location` and `:presign_options` in their block versions are
125
- yielded an instance of [Roda request], which is a subclass of `Rack::Request`.
126
-
127
- See the [Direct Uploads to S3] guide for further instructions on how to hook
128
- the presigned uploads to a form.
129
-
130
- ## Allowed storages
131
-
132
- By default only uploads to `:cache` are allowed, to prevent the possibility of
133
- having orphan files in your main storage. But you can allow more storages:
134
-
135
- ```rb
136
- plugin :direct_upload, allowed_storages: [:cache, :store]
137
- ```
138
-
139
- ## Customizing endpoint
140
-
141
- Since the endpoint is a [Roda] app, it is very customizable. For example, you
142
- can add a Rack middleware to change the response status and headers:
143
-
144
- ```rb
145
- class ShrineUploadMiddleware
146
- def initialize(app)
147
- @app = app
148
- end
149
-
150
- def call(env)
151
- result = @app.call(env)
152
-
153
- if result[0] == 200 && env["PATH_INFO"].end_with?("upload")
154
- result[0] = 201
155
- result[1]["Location"] = Shrine.uploaded_file(result[2].first).url
156
- end
157
-
158
- result
159
- end
160
- end
161
-
162
- Shrine::UploadEndpoint.use ShrineUploadMiddleware
163
- ```
164
-
165
- Upon subclassing uploader the upload endpoint is also subclassed. You can also
166
- call the plugin again in an uploader subclass to change its configuration.
167
-
168
- [direct_upload]: /lib/shrine/plugins/direct_upload.rb
169
- [Roda]: https://github.com/jeremyevans/roda
170
- [Uppy]: https://uppy.io
171
- [Roda request]: http://roda.jeremyevans.net/rdoc/classes/Roda/RodaPlugins/Base/RequestMethods.html
172
- [Direct Uploads to S3]: /doc/direct_s3.md#readme