shrine 2.14.0 → 2.15.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 (149) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +384 -374
  3. data/README.md +132 -63
  4. data/doc/advantages.md +191 -109
  5. data/doc/attacher.md +1 -1
  6. data/doc/carrierwave.md +4 -4
  7. data/doc/creating_storages.md +2 -2
  8. data/doc/design.md +2 -2
  9. data/doc/direct_s3.md +3 -3
  10. data/doc/metadata.md +1 -1
  11. data/doc/multiple_files.md +2 -2
  12. data/doc/paperclip.md +3 -3
  13. data/doc/plugins/activerecord.md +92 -0
  14. data/doc/plugins/add_metadata.md +93 -0
  15. data/doc/plugins/backgrounding.md +148 -0
  16. data/doc/plugins/backup.md +29 -0
  17. data/doc/plugins/cached_attachment_data.md +23 -0
  18. data/doc/plugins/copy.md +22 -0
  19. data/doc/plugins/data_uri.md +92 -0
  20. data/doc/plugins/default_storage.md +16 -0
  21. data/doc/plugins/default_url.md +33 -0
  22. data/doc/plugins/default_url_options.md +22 -0
  23. data/doc/plugins/delete_promoted.md +10 -0
  24. data/doc/plugins/delete_raw.md +16 -0
  25. data/doc/plugins/derivation_endpoint.md +747 -0
  26. data/doc/plugins/determine_mime_type.md +64 -0
  27. data/doc/plugins/direct_upload.md +170 -0
  28. data/doc/plugins/download_endpoint.md +83 -0
  29. data/doc/plugins/dynamic_storage.md +20 -0
  30. data/doc/plugins/hooks.md +56 -0
  31. data/doc/plugins/included.md +15 -0
  32. data/doc/plugins/infer_extension.md +57 -0
  33. data/doc/plugins/keep_files.md +20 -0
  34. data/doc/plugins/logging.md +39 -0
  35. data/doc/plugins/metadata_attribues.md +43 -0
  36. data/doc/plugins/migration_helpers.md +58 -0
  37. data/doc/plugins/module_include.md +40 -0
  38. data/doc/plugins/moving.md +17 -0
  39. data/doc/plugins/multi_delete.md +18 -0
  40. data/doc/plugins/parallelize.md +14 -0
  41. data/doc/plugins/parsed_json.md +9 -0
  42. data/doc/plugins/presign_endpoint.md +133 -0
  43. data/doc/plugins/pretty_location.md +29 -0
  44. data/doc/plugins/processing.md +68 -0
  45. data/doc/plugins/rack_file.md +49 -0
  46. data/doc/plugins/rack_response.md +96 -0
  47. data/doc/plugins/recache.md +27 -0
  48. data/doc/plugins/refresh_metadata.md +31 -0
  49. data/doc/plugins/remote_url.md +104 -0
  50. data/doc/plugins/remove_attachment.md +16 -0
  51. data/doc/plugins/remove_invalid.md +9 -0
  52. data/doc/plugins/restore_cached_data.md +14 -0
  53. data/doc/plugins/sequel.md +64 -0
  54. data/doc/plugins/signature.md +49 -0
  55. data/doc/plugins/store_dimensions.md +68 -0
  56. data/doc/plugins/tempfile.md +40 -0
  57. data/doc/plugins/upload_endpoint.md +123 -0
  58. data/doc/plugins/upload_options.md +28 -0
  59. data/doc/plugins/validation_helpers.md +129 -0
  60. data/doc/plugins/versions.md +179 -0
  61. data/doc/processing.md +217 -247
  62. data/doc/refile.md +3 -3
  63. data/doc/release_notes/1.0.0.md +143 -0
  64. data/doc/release_notes/1.1.0.md +184 -0
  65. data/doc/release_notes/1.2.0.md +37 -0
  66. data/doc/release_notes/1.3.0.md +90 -0
  67. data/doc/release_notes/1.4.0.md +167 -0
  68. data/doc/release_notes/1.4.1.md +9 -0
  69. data/doc/release_notes/1.4.2.md +20 -0
  70. data/doc/release_notes/2.0.0.md +173 -0
  71. data/doc/release_notes/2.0.1.md +12 -0
  72. data/doc/release_notes/2.1.0.md +59 -0
  73. data/doc/release_notes/2.1.1.md +8 -0
  74. data/doc/release_notes/2.10.0.md +52 -0
  75. data/doc/release_notes/2.10.1.md +6 -0
  76. data/doc/release_notes/2.11.0.md +69 -0
  77. data/doc/release_notes/2.12.0.md +65 -0
  78. data/doc/release_notes/2.13.0.md +146 -0
  79. data/doc/release_notes/2.14.0.md +278 -0
  80. data/doc/release_notes/2.15.0.md +82 -0
  81. data/doc/release_notes/2.2.0.md +98 -0
  82. data/doc/release_notes/2.3.0.md +50 -0
  83. data/doc/release_notes/2.3.1.md +10 -0
  84. data/doc/release_notes/2.4.0.md +87 -0
  85. data/doc/release_notes/2.4.1.md +29 -0
  86. data/doc/release_notes/2.5.0.md +130 -0
  87. data/doc/release_notes/2.6.0.md +254 -0
  88. data/doc/release_notes/2.6.1.md +14 -0
  89. data/doc/release_notes/2.7.0.md +180 -0
  90. data/doc/release_notes/2.8.0.md +95 -0
  91. data/doc/release_notes/2.9.0.md +82 -0
  92. data/doc/retrieving_uploads.md +1 -1
  93. data/doc/storage/file_system.md +96 -0
  94. data/doc/storage/s3.md +293 -0
  95. data/doc/validation.md +1 -1
  96. data/lib/shrine/plugins/_urlsafe_serialization.rb +33 -125
  97. data/lib/shrine/plugins/activerecord.rb +0 -78
  98. data/lib/shrine/plugins/add_metadata.rb +0 -80
  99. data/lib/shrine/plugins/backgrounding.rb +0 -134
  100. data/lib/shrine/plugins/backup.rb +0 -22
  101. data/lib/shrine/plugins/cached_attachment_data.rb +0 -15
  102. data/lib/shrine/plugins/copy.rb +0 -14
  103. data/lib/shrine/plugins/data_uri.rb +0 -73
  104. data/lib/shrine/plugins/default_storage.rb +0 -11
  105. data/lib/shrine/plugins/default_url.rb +0 -25
  106. data/lib/shrine/plugins/default_url_options.rb +0 -16
  107. data/lib/shrine/plugins/delete_promoted.rb +0 -6
  108. data/lib/shrine/plugins/delete_raw.rb +0 -10
  109. data/lib/shrine/plugins/derivation_endpoint.rb +652 -0
  110. data/lib/shrine/plugins/determine_mime_type.rb +1 -85
  111. data/lib/shrine/plugins/direct_upload.rb +0 -155
  112. data/lib/shrine/plugins/download_endpoint.rb +11 -73
  113. data/lib/shrine/plugins/dynamic_storage.rb +0 -17
  114. data/lib/shrine/plugins/hooks.rb +0 -48
  115. data/lib/shrine/plugins/included.rb +0 -12
  116. data/lib/shrine/plugins/infer_extension.rb +0 -49
  117. data/lib/shrine/plugins/keep_files.rb +0 -19
  118. data/lib/shrine/plugins/logging.rb +0 -39
  119. data/lib/shrine/plugins/metadata_attributes.rb +0 -35
  120. data/lib/shrine/plugins/migration_helpers.rb +0 -50
  121. data/lib/shrine/plugins/module_include.rb +0 -32
  122. data/lib/shrine/plugins/moving.rb +0 -12
  123. data/lib/shrine/plugins/multi_delete.rb +0 -13
  124. data/lib/shrine/plugins/parallelize.rb +0 -8
  125. data/lib/shrine/plugins/parsed_json.rb +0 -5
  126. data/lib/shrine/plugins/presign_endpoint.rb +2 -117
  127. data/lib/shrine/plugins/pretty_location.rb +0 -22
  128. data/lib/shrine/plugins/processing.rb +0 -55
  129. data/lib/shrine/plugins/rack_file.rb +0 -39
  130. data/lib/shrine/plugins/rack_response.rb +0 -81
  131. data/lib/shrine/plugins/recache.rb +0 -21
  132. data/lib/shrine/plugins/refresh_metadata.rb +0 -24
  133. data/lib/shrine/plugins/remote_url.rb +0 -85
  134. data/lib/shrine/plugins/remove_attachment.rb +0 -10
  135. data/lib/shrine/plugins/remove_invalid.rb +0 -6
  136. data/lib/shrine/plugins/restore_cached_data.rb +0 -10
  137. data/lib/shrine/plugins/sequel.rb +0 -54
  138. data/lib/shrine/plugins/signature.rb +0 -37
  139. data/lib/shrine/plugins/store_dimensions.rb +0 -63
  140. data/lib/shrine/plugins/tempfile.rb +4 -35
  141. data/lib/shrine/plugins/upload_endpoint.rb +2 -109
  142. data/lib/shrine/plugins/upload_options.rb +0 -20
  143. data/lib/shrine/plugins/validation_helpers.rb +0 -36
  144. data/lib/shrine/plugins/versions.rb +0 -156
  145. data/lib/shrine/storage/file_system.rb +0 -77
  146. data/lib/shrine/storage/s3.rb +0 -249
  147. data/lib/shrine/version.rb +1 -1
  148. data/shrine.gemspec +2 -2
  149. metadata +86 -6
@@ -0,0 +1,52 @@
1
+ ## New features
2
+
3
+ * The `:mini_magick` analyzer has been added to the `store_dimensions` plugin,
4
+ which uses the [MiniMagick] gem to extract image dimensions.
5
+
6
+ * The `:ruby_vips` analyzer has been added to the `store_dimensions` plugin,
7
+ which uses the [ruby-vips] gem to extract image dimensions.
8
+
9
+ * The `:fastimage` analyzer has been added to the `determine_mime_type` plugin,
10
+ which uses the [FastImage] gem to determine the MIME type of the file.
11
+
12
+ * `Shrine::UploadedFile#download` now accepts a block for downloading an
13
+ uploaded file temporarily. This is useful when wanting to validate whether an
14
+ uploaded image is valid or corrupted, or when generating thumbnails.
15
+
16
+ ```rb
17
+ uploaded_file.download do |tempfile|
18
+ # ...
19
+ end # tempfile is deleted
20
+ ```
21
+
22
+ ## Other improvements
23
+
24
+ * It's not required that IO objects respond to `#size` anymore. This is
25
+ useful when uploading streams of data where the size is not known.
26
+
27
+ * The S3 storage now supports IO objects with unknown size. Under the hood it
28
+ will use multipart upload.
29
+
30
+ * The logger is now properly inherited and shared between `Shrine` subclasses.
31
+
32
+ * The attachment URL generated by `download_endpoint` now stays the same
33
+ regardless of the order of elements in the metadata hash. Previously it could
34
+ change after the uploaded file data is loaded from the database, because the
35
+ order of the metadata hash elements would change, which is not desirable for
36
+ caching.
37
+
38
+ ## Backwards compatibility
39
+
40
+ * The `:rack_mime` extension inferrer has been removed from the
41
+ `infer_extension` plugin, due to not having acceptable behaviour. The new
42
+ default extension inferrer is `:mime_types`.
43
+
44
+ * The `:heroku` formatter in the `logging` plugin has been soft-renamed to
45
+ `:logfmt`. The `:heroku` alias will stop being supported in Shrine 3.
46
+
47
+ * The `Shrine::IO_METHODS` constant has been depreacted, and will become
48
+ private in Shrine 3.
49
+
50
+ [MiniMagick]: https://github.com/minimagick/minimagick
51
+ [ruby-vips]: https://github.com/libvips/ruby-vips
52
+ [FastImage]: https://github.com/sdsykes/fastimage
@@ -0,0 +1,6 @@
1
+ ## Regressions
2
+
3
+ * Determining MIME type from file extension (using `:mime_types` or
4
+ `:mini_mime` analyzers) when file is empty now works again. This was the
5
+ behaviour prior to version 2.7.0, but 2.7.0 introduced a regression where
6
+ `nil` was returned for empty files, even if they had an extension.
@@ -0,0 +1,69 @@
1
+ ## New features
2
+
3
+ * `Shrine::UploadedFile#stream` has been added for streaming the uploaded
4
+ content to a writable destination.
5
+
6
+ ```rb
7
+ uploaded_file.stream(StringIO.new)
8
+ # or
9
+ uploaded_file.stream("/path/to/destination")
10
+ ```
11
+
12
+ * `Shrine.with_file` has been added for temporarily converting an IO-like
13
+ object into a file. This is useful when wanting to extract metadata using an
14
+ analyzer which requires the source file to be on disk.
15
+
16
+ ```rb
17
+ add_metadata do |io, context|
18
+ movie = Shrine.with_file(io) { |file| FFMPEG::Movie.new(file.path) }
19
+
20
+ { "duration" => movie.duration,
21
+ "bitrate" => movie.bitrate,
22
+ "resolution" => movie.resolution,
23
+ "frame_rate" => movie.frame_rate }
24
+ end
25
+ ```
26
+
27
+ * The `upload_endpoint` plugin now accepts the `Content-MD5` request header,
28
+ in which case it will verify the provided checksum.
29
+
30
+ * `Shrine::Storage::S3#presign` now accepts `method: :put` for changing from a
31
+ POST to a PUT presigned URL. PUT presigned URLs are generally preferred as
32
+ they support more parameters, such as `:content_md5` for specifying the
33
+ checksum.
34
+
35
+ ## Other improvements
36
+
37
+ * `Shrine::UploadedFile#download` will now reuse an already opened file, and
38
+ in this case will simply rewind it after it's finished.
39
+
40
+ * The `:mini_magick` and `:ruby_vips` dimensions analyzers now silently fail
41
+ on processing errors, to allow validations to be reached when invalid file
42
+ is attached.
43
+
44
+ * The `#presign` storage method can now return a Hash. This means it's not
45
+ required for result to be wrapped in a `Struct` or `OpenStruct` anymore.
46
+
47
+ * The `Shrine::Storage::S3#presign` now also returns a `:method` value
48
+ indicating the HTTP verb that needs to be used for the direct upload.
49
+
50
+ * The bucket name is not removed from S3 URL path anymore when both `:host`
51
+ and `:force_path_style` are set in `Shrine::Storage::S3#url`.
52
+
53
+ ## Regressions
54
+
55
+ * The MIME type is now correctly determined on empty files for `:mime_types`
56
+ and `:mini_mime` analyzers. This regression was introduced in Shrine 2.7.0.
57
+
58
+ ## Backwards compatibility
59
+
60
+ * The `direct_upload` plugin has been deprecated in favour of `upload_endpoint`
61
+ and `presign_endpoint` plugins. The `direct_upload` plugin will be removed in
62
+ Shrine 3.
63
+
64
+ * `Storage#presign` returning an object that doesn't respond to `#to_h` is now
65
+ deprecated, the support for these objects will be removed in Shrine 3.
66
+
67
+ * `Shrine::Storage::S3#presign` now returns a `Struct` instead of an
68
+ `Aws::S3::PresignedPost` object. Any applications relying on any methods
69
+ other than `#url` and `#fields` will have to update their code.
@@ -0,0 +1,65 @@
1
+ ## New features
2
+
3
+ * The `Shrine::Attacher#assign_remote_url` method has been added, which acts the
4
+ same as `#remote_url=` but allows you to also dynamically provide options to
5
+ the underlying downloader (`Down.download` by default).
6
+
7
+ ```rb
8
+ attacher.assign_remote_url("https://example.com/image.jpg", downloader: { 'Cookie' => 'abc123' })
9
+ ```
10
+
11
+ * The `Shrine::UploadedFile#download_url` method has been added to the
12
+ `download_endpoint` plugin for explicitly generating the file URL through
13
+ the download endpoint.
14
+
15
+ * The `:redirect` option has been added to `download_endpoint` plugin, which
16
+ makes download URLs redirect directly to the uploaded file on its storage.
17
+ This allows you to avoding streaming the file through your app, and thus not
18
+ having it impact your request throughput.
19
+
20
+ * The `Shrine::Plugins::ValidationHelpers::PRETTY_FILESIZE` callbable has been
21
+ added, which takes the filesize in bytes and returns the representation in
22
+ correct unit. This can be used when providing custom validation error messages.
23
+
24
+ ```rb
25
+ pretty_filesize = Shrine::Plugins::ValidationHelpers::PRETTY_FILESIZE
26
+ pretty_filesize.call(1*1024) #=> "1.0 KB"
27
+ pretty_filesize.call(1.5*1024*1024) #=> "1.5 MB"
28
+ pretty_filesize.call(2*1024*1024*1024) #=> "2.0 GB"
29
+ ```
30
+
31
+ ## Other improvements
32
+
33
+ * The `Shrine::Storage::FileSystem#open` now forwards any additional options to
34
+ `File.open`.
35
+
36
+ * The `Shrine::Storage::S3#open` method now accepts the `:rewindable` option to
37
+ disable caching read content to disk.
38
+
39
+ * In validation error messages in filesize validators in the
40
+ `validation_helpers` plugin show specified limits in the appropriate unit,
41
+ instead of always using megabytes.
42
+
43
+ * `Shrine::UploadedFile#open` will now always open a new IO object, and close
44
+ the previous one. This way the uploaded file will be reopened if it's closed.
45
+
46
+ * Fixed possible encoding issues in `Shrine::Storage::S3#upload` when filesize
47
+ is unknown.
48
+
49
+ * The registered storage resolvers in the `dynamic_storage` plugin are now
50
+ correctly inherited upon subclassing.
51
+
52
+ * The `:file` MIME type analyzer from `determine_mime_type` plugin will now
53
+ raise an explicit `Shrine::Error` when the subprocess from the shell command
54
+ failed to be spawned.
55
+
56
+ * `Attacher#data_uri=` and `Attacher#remote_url=` in addition to `""` now also
57
+ ignore `nil` values, instead of raising an exception.
58
+
59
+ ## Backwards compatibility
60
+
61
+ * The `:storages` option has been deprecated in the `download_endpoint` plugin
62
+ in favour of the new `Shrine::UploadedFile#download_url` method.
63
+
64
+ * The deprecation of assigning cached versions has been undone, as it can be a
65
+ useful feature.
@@ -0,0 +1,146 @@
1
+ ## New features
2
+
3
+ * The S3 object URLs can now be signed with a custom signer. This enables
4
+ serving private objects via AWS CloudFront by signing the URLs with the
5
+ signer from the `aws-sdk-cloudfront` gem.
6
+
7
+ ```rb
8
+ require "aws-sdk-cloudfront"
9
+
10
+ signer = Aws::CloudFront::UrlSigner.new(
11
+ key_pair_id: "cf-keypair-id",
12
+ private_key_path: "./cf_private_key.pem",
13
+ )
14
+
15
+ Shrine::Storage::S3.new(signer: signer.method(:signed_url))
16
+ ```
17
+
18
+ * To make your S3 storage public, previously you needed to do two things: set
19
+ the `acl: "public-read"` upload option and set pass `public: true` when
20
+ generating a URL.
21
+
22
+ ```rb
23
+ Shrine.storages = {
24
+ cache: Shrine::Storage::S3.new(upload_options: { acl: "public-read" }, **options),
25
+ store: Shrine::Storage::S3.new(upload_options: { acl: "public-read" }, **options),
26
+ }
27
+
28
+ Shrine.plugin :default_url_options,
29
+ cache: { public: true },
30
+ store: { public: true }
31
+ ```
32
+
33
+ Now you can achieve the same thing just by setting `public: true` when
34
+ initializing the S3 storage.
35
+
36
+ ```rb
37
+ Shrine.storages = {
38
+ cache: Shrine::Storage::S3.new(public: true, **options),
39
+ store: Shrine::Storage::S3.new(public: true, **options),
40
+ }
41
+ ```
42
+
43
+ * The `:force` option has been added to the `infer_extension` plugin, which
44
+ makes the extension always determined from the MIME type, regardless of
45
+ whether it exists or not.
46
+
47
+ ```rb
48
+ Shrine.plugin :infer_extension, force: true
49
+ ```
50
+
51
+ This is useful for when you want to normalize the file extensions of uploaded
52
+ files.
53
+
54
+ ```rb
55
+ uploader.upload(File.open("image.jpg")) #
56
+ uploader.upload(File.open("image.jpeg")) # all these will be uploaded with a .jpeg extension
57
+ uploader.upload(File.open("image.JPG")) #
58
+ ```
59
+
60
+ * `Shrine#upload` now accepts a `:metadata` option for manually overrding the
61
+ extracted metadata.
62
+
63
+ ```rb
64
+ uploaded_file = uploader.upload(file, metadata: { "filename" => "my-file.txt" })
65
+ uploaded_file.original_filename #=> "my-file.txt"
66
+ ```
67
+
68
+ Furthermore, `Shrine::Attacher#assign` now forwards any additional options to
69
+ `Shrine#upload`, so you can also override metadata when attaching files.
70
+
71
+ ```rb
72
+ photo.image_attacher.assign(file, metadata: { "mime_type" => "text/plain" })
73
+ ```
74
+
75
+ ## Other improvements
76
+
77
+ * It's now possible to use an S3 endpoint which requires bucket name to be in
78
+ the URI path (e.g. Minio) with CDNs where bucket name shouldn't be in the URI
79
+ path (e.g. CloudFront). Since version 2.11.0, when initializing
80
+ `Shrine::Storage::S3` with `:endpoint` with `:force_path_style`, generating
81
+ an URL with a `:host` returned an URI with bucket name in the path. This
82
+ introduced a regression for anyone relying on previous behaviour, so that
83
+ change has been reverted, and this is the current behaviour:
84
+
85
+ ```rb
86
+ s3 = Shrine::Storage::S3.new(endpoint: "https://minio.example.com")
87
+ s3.url("foo") #=> "https://my-s3-endpoint.com/foo"
88
+ s3.url("foo", host: "https://123.cloudfront.net") #=> "https://123.cloudfront.net/foo"
89
+
90
+ s3 = Shrine::Storage::S3.new(endpoint: "https://my-s3-endpoint.com", force_path_style: true, **options)
91
+ s3.url("foo") #=> "https://my-s3-endpoint.com/my-bucket/foo"
92
+ s3.url("foo", host: "https://123.cloudfront.net") #=> "https://123.cloudfront.net/foo"
93
+ ```
94
+
95
+ * The `:host` option to `Shrine::Storage::S3#url` now handles URLs with
96
+ path prefixes, provided that the URL ends with a slash.
97
+
98
+ ```rb
99
+ # old behaviour
100
+ s3.url("foo", host: "https://example.com/prefix/") #=> "https://example.com/foo"
101
+ # new behaviour
102
+ s3.url("foo", host: "https://example.com/prefix/") #=> "https://example.com/prefix/foo"
103
+ ```
104
+
105
+ * Fixed error that would happen when uploading a file with a filename that had
106
+ certain combination of UTF-8 characters to `upload_endpoint`.
107
+
108
+ * The `Content-Type` header in `upload_endpoint` and `presign_endpoint`
109
+ responses now specifies `charset=utf-8`.
110
+
111
+ * `Shrine::Storage::S3` now uses `Aws::S3::Object#upload_stream` if available
112
+ when uploading large IO streams which are not file objects, which uses
113
+ parallelized multipart upload. This can make such uploads finish up to 2x
114
+ faster.
115
+
116
+ * `Shrine::Storage::S3` now uses `Aws::S3::Object#upload_stream` if available
117
+ when uploading files of unknown size.
118
+
119
+ * The `file` command could sometimes exit successfully, but return a `cannot
120
+ open: No such file or directory` on stdout. This is now detected and a
121
+ `Shrine::Error` is raised.
122
+
123
+ * The `upload_endpoint` now returns `Upload Not Valid` error message when file
124
+ parameter was present but not in correct format (previously `Upload Not
125
+ Found` was returned, which was a bit misleading).
126
+
127
+ ## Backwards compatibility
128
+
129
+ * When `Shrine::Storage::S3` is initialized with `:endpoint` with
130
+ `:force_path_style`, a file URL generated with a `:host` will not include the
131
+ bucket name in the URL path anymore. Users relying on this behaviour should
132
+ update their code to include the bucket name in the `:host` URL path.
133
+
134
+ ```rb
135
+ s3.url("foo", host: "https://example.com/my-bucket/")
136
+ ```
137
+
138
+ * Using aws-sdk-s3 older than 1.14 with `Shrine::Storage::S3` when uploading
139
+ files with unknown size is now deprecated and won't be supported in Shrine 3.
140
+
141
+ Also, in this case `Shrine::Storage::S3` will now first copy the whole file
142
+ onto disk before uploading it (previously only a chunk of the input file was
143
+ copied to disk at a time).
144
+
145
+ If you're uploading files of unknown size (ones where `#size` is not defined
146
+ or returns `nil`), you should upgrade to aws-sdk-s3 1.14 or higher.
@@ -0,0 +1,278 @@
1
+ ## New features
2
+
3
+ * `Shrine::Storage::S3` now accepts a `:client` option for specifying an AWS
4
+ SDK client object. This allows the user to configure client-side encryption by
5
+ passing a `Aws::S3::Encryption::Client` object:
6
+
7
+ ```rb
8
+ client = Aws::S3::Encryption::Client.new(
9
+ kms_key_id: "alias/my-key",
10
+ **options
11
+ )
12
+
13
+ Shrine::Storage::S3.new(client: client, bucket: "my-bucket")
14
+ ```
15
+
16
+ * The metadata blocks in the `add_metadata` plugin now have previous metadata
17
+ available to them in `context[:metadata]` (thanks to @jrochkind).
18
+
19
+ ```rb
20
+ add_metadata :foo do |io, context|
21
+ context[:metadata] #=>
22
+ # {
23
+ # "filename" => "nature.jpg",
24
+ # "size" => 123,
25
+ # "mime_type" => "image/jpeg"
26
+ # }
27
+
28
+ "foo"
29
+ end
30
+
31
+ add_metadata :bar do |io, context|
32
+ context[:metadata] #=>
33
+ # {
34
+ # "filename" => "nature.jpg",
35
+ # "size" => 123,
36
+ # "mime_type" => "image/jpeg",
37
+ # "foo" => "foo"
38
+ # }
39
+
40
+ "bar"
41
+ end
42
+ ```
43
+
44
+ * `UploadedFile#to_rack_response` from `rack_response` plugin now accepts
45
+ `:type` and `:filename` options for overriding the values in metadata that
46
+ would otherwise be used for the `Content-Type` and `Content-Disposition`
47
+ response headers.
48
+
49
+ ```rb
50
+ status, headers, body = uploaded_file.to_rack_response(
51
+ type: "text/csv; charset=utf-8",
52
+ filename: "export.csv",
53
+ )
54
+
55
+ headers["Content-Type"] #=> "text/csv; charset=utf-8"
56
+ headers["Content-Disposition"] #=> "inline; filename=\"export.csv\""
57
+ ```
58
+
59
+ * `Shrine.data_uri` from `data_uri` plugin now accepts a `:filename` string,
60
+ which will be returned in
61
+ `Shrine::Plugins::DataUri::DataFile#original_filename`.
62
+
63
+ ```rb
64
+ io = Shrine.data_uri("data:,content", filename: "foo.txt")
65
+ io.original_filename #=> "foo.txt"
66
+ ```
67
+
68
+ * `UploadedFile#download_url` from `download_endpoint` plugin now accepts a
69
+ `:host` option. Previously it was only possible to configure the URL host on
70
+ the plugin level.
71
+
72
+ ```rb
73
+ uploaded_file.download_url(host: "https://example.com")
74
+ ```
75
+
76
+ * `Attacher#cached?` and `Attacher#stored?` now accept an optional uploaded
77
+ file parameter, and return whether the given uploaded file is uploaded to the
78
+ temporary or permanent storage of the attacher (thanks to @jrochkind).
79
+
80
+ ## Performance improvements
81
+
82
+ * `UploadedFile#download` doesn't call `Storage#download` anymore (only
83
+ `Storage#open`). This improves performance when the uploaded file is
84
+ already opened, e.g. when using `refresh_metadata` plugin and
85
+ `Shrine.with_file` during metadata extraction. Instead of performing
86
+ a new download request, `UploadedFile#download` will in this case reuse the
87
+ already opened IO object.
88
+
89
+ * Added `tempfile` plugin that makes it easier to avoid copying the
90
+ `UploadedFile` to disk multiple times during promotion. For example, in the
91
+ following code the uploaded file will be downloaded to disk only once
92
+ instead of three times.
93
+
94
+ ```rb
95
+ Shrine.plugin :tempfile
96
+ ```
97
+ ```rb
98
+ class MyUploader < Shrine
99
+ plugin :processing
100
+ plugin :add_metadata
101
+ plugin :refresh_metadata
102
+
103
+ process(:store) do |io, context|
104
+ io.open do
105
+ io.refresh_metadata!
106
+
107
+ processor = ImageProcessing::Vips.source(io.tempfile)
108
+ # ... processing ...
109
+ end
110
+ end
111
+
112
+ add_metadata :foo do |io, context|
113
+ Shrine.with_file(io) { "..." } unless context[:action] == :store
114
+ end
115
+
116
+ add_metadata :bar do |io, context|
117
+ Shrine.with_file(io) { "..." } unless context[:action] == :store
118
+ end
119
+ end
120
+ ```
121
+
122
+ * `UploadedFile#refresh_metadata!` from `refresh_metadata` plugin now detects
123
+ when the uploaded file is already opened and in that case doesn't re-open the
124
+ file. This makes code like this faster:
125
+
126
+ ```rb
127
+ uploaded_file.open do
128
+ uploaded_file.refresh_metadata! # doesn't re-open the file anymore
129
+ end
130
+ ```
131
+
132
+ * The `rack_response` plugin now integrates with `Rack::Sendfile` middleware
133
+ when `Shrine::Storage::FileSystem` is used. It does so by making the response
134
+ body respond to `#to_path`.
135
+
136
+ * `#<name>_attacher` doesn't look up the attachment class every time it's
137
+ called with a new model instance anymore, making it slightly faster (thanks
138
+ to @printercu).
139
+
140
+ ## Other improvements
141
+
142
+ * The `lib/shrine.rb` file has been split into `lib/shrine.rb`,
143
+ `lib/shrine/uploaded_file.rb`, `lib/shrine/attacher.rb`,
144
+ `lib/shrine/attachment.rb`, and `lib/shrine/plugins.rb` (thanks to
145
+ @printercu).
146
+
147
+ * `Shrine::Storage::S3` and `rack_response` plugin now use the
148
+ [content_disposition] gem for generating correctly formatted
149
+ `Content-Disposition` header values.
150
+
151
+ * The `S3#download` and `S3#open` methods now work correctly with server-side
152
+ encryption (as long as the necessary `:sse_*` parameters are passed in).
153
+
154
+ * Fixed `FileSystem#clear!` not working with symlinks (at least on MRI).
155
+
156
+ * Fixed `add_metadata` plugin overriding previously defined metadata
157
+ blocks when loaded again.
158
+
159
+ * Fixed `processing` plugin overriding previously defined processing
160
+ blocks when loaded again.
161
+
162
+ * Fixed `backgrounding` plugin erroring when temorary/permanent storage is
163
+ declared in `Shrine::Attachment.new` and there are no `:cache` or `:store`
164
+ storages defined.
165
+
166
+ * Fixed `UploadedFile#extension` (and thus the tempfile in
167
+ `UploadedFile#download`) including URL query parameters in the file extension
168
+ when `Shrine::Storage::Url` is used (`shrine-url` gem) with URLs that have
169
+ query parameters (thanks to @jrochkind).
170
+
171
+ * Fixed `backgrounding` plugin aborting promotion when cached file metadata was
172
+ refreshed in the processing block and Active Record JSON column was used.
173
+ - `refresh_metadata` plugin now avoids mutating the uploaded file data hash
174
+ - `backgrounding` plugin now continues promotion if cached file metadata has changed
175
+
176
+ * The `Shrine.data_uri` method from the `data_uri` plugin now picks up media
177
+ type parameters from the data URI and includes them in
178
+ `Shrine::Plugins::DataUri::DataFile#content_type`.
179
+
180
+ ```rb
181
+ io = Shrine.data_uri("data:text/plain;charset=utf-8,content")
182
+ io.content_type #=>
183
+ # BEFORE: "text/plain"
184
+ # AFTER: "text/plain;charset=utf-8"
185
+ ```
186
+
187
+ * When fetching `mime_type` metadata value from `io.content_type`, any media
188
+ type parameters are now stripped. This means that if the user uploads a text
189
+ file with a `Content-Type` of `text/plain; charset=utf-8`, the `mime_type`
190
+ will now correctly be stored as `text/plain`. This fixes any MIME type
191
+ validations that might not have been passing due to additional media type
192
+ parameters.
193
+
194
+ * When `determine_mime_type` plugin is loaded with the `:default` analyzer,
195
+ a warning is not printed anymore.
196
+
197
+ * When `Shrine::Storage::S3` is initialized with `bucket: nil`, an appropriate
198
+ error message is now raised.
199
+
200
+ * The `:content_type` MIME type analyzer has been added to the
201
+ `Shrine.mime_type_analyzers` hash in `determine_mime_type` plugin (previously
202
+ known as `:default`).
203
+
204
+ ## Documentation
205
+
206
+ * The [Retrieving Uploads] guide has been added.
207
+
208
+ ## Backwards compatibility
209
+
210
+ * Support for MRI 2.1 and MRI 2.2 has been dropped.
211
+
212
+ * `Shrine::Plugins::Base` module has been removed and contained modules have
213
+ been moved to `InstanceMethods` and `ClassMethods` modules inside the
214
+ corresponding core classes. This should not break anything unless you were
215
+ referencing those modules directly.
216
+
217
+ ```rb
218
+ Shrine::Plugins::Base::InstanceMethods => Shrine::InstanceMethods
219
+ Shrine::Plugins::Base::ClassMethods => Shrine::ClassMethods
220
+ Shrine::Plugins::Base::FileMethods => Shrine::UploadedFile::InstanceMethods
221
+ Shrine::Plugins::Base::FileClassMethods => Shrine::UploadedFile::ClassMethods
222
+ Shrine::Plugins::Base::AttacherMethods => Shrine::Attacher::InstanceMethods
223
+ Shrine::Plugins::Base::AttacherClassMethods => Shrine::Attacher::ClassMethods
224
+ Shrine::Plugins::Base::AttachmentMethods => Shrine::Attachment::InstanceMethods
225
+ Shrine::Plugins::Base::AttachmentClassMethods => Shrine::Attachment::ClassMethods
226
+ ```
227
+
228
+ * `UploadedFile#download` doesn't call `Storage#download` anymore, it now
229
+ always calls `Storage#open`. Since `Storage#download` is not used anywhere
230
+ else in Shrine, storages can remove the `#download` method.
231
+
232
+ * `Shrine::Storage::S3#download` has been deprecated and will be removed in
233
+ Shrine 3.
234
+
235
+ * In `Shrine::Storage::S3#upload`, `#open`, and `#presign` it's now deprecated
236
+ to pass the `Content-Disposition` header value with non-ASCII characters.
237
+ Starting with Shrine 3 these characters won't be escaped anymore. You should
238
+ now use the [content_disposition] gem to properly format the
239
+ `Content-Disposition` header value.
240
+
241
+ ```rb
242
+ # BAD:
243
+ plugin :default_url_options, store: -> (io, **options) do
244
+ { response_content_disposition: "attachment; filename=\"#{io.original_filename}\"" }
245
+ end
246
+
247
+ # GOOD:
248
+ plugin :default_url_options, store: -> (io, **options) do
249
+ { response_content_disposition: ContentDisposition.attachment(io.original_filename) }
250
+ end
251
+ ```
252
+
253
+ * The `mime_type` metadata value will now strip any additional media type
254
+ parameters such as `charset` from `io.content_type`. If you were relying on
255
+ this behaviour, you will need to update your code.
256
+
257
+ * In `determine_mime_type` plugin, the `:default` MIME type analyzer has been
258
+ renamed to `:content_type`. The `:default` alias will stop being supported in
259
+ Shrine 3.
260
+
261
+ ```rb
262
+ plugin :determine_mime_type, analyzer: :default
263
+ # should be changed to
264
+ plugin :determine_mime_type, analyzer: :content_type
265
+ ```
266
+
267
+ * The `UploadedFile` private methods that were added by the `rack_response`
268
+ plugin have now been moved to an internal class (leaving only
269
+ `#to_rack_response`). If you've are currently overriding any of these private
270
+ methods, you'll need to update your code.
271
+
272
+ * The `UploadedFile` private methods that were added by the `download_endpoint`
273
+ plugin have now been moved to an internal class (leaving only
274
+ `#download_url`). If you've are currently overriding any of these private
275
+ methods, you'll need to update your code.
276
+
277
+ [Retrieving Uploads]: /doc/retrieving_uploads.md#readme
278
+ [content_disposition]: https://github.com/shrinerb/content_disposition