Commit Graph

51 Commits

Author SHA1 Message Date
chaadow
cb3fdaf8e4 Fix representation proxy for untracked variants
`ActiveStorage::Variant`, the class used to handle untracked variants,
is lacking some methods to make it compliant with
`ActiveStorage::Representations::ProxyController#send_blob_stream`.

This commit fixes the proxying of untracked variant by adding the
missing methods.
2023-11-20 19:57:01 +01:00
Petrik
1e23fff1a1 Remove unused methods on ActiveStorage::Variant
These methods were added in b221a4dc43368a1b6f00476f7c5f6047c5c7eea4
But they don't seem to be used by Rails internally or have any tests, so
I assume they were added by accident?
As they both seem to be marked as :nodoc: on ActiveStorage::Blob, we can
remove them without a deprecation warning.

If we decide to keep these methods, they should be added to
ActiveStorage::VariantWithRecord as well. No one complaining about there
methods missing on ActiveStorage::VariantWithRecord is another reason
these methods aren't used.
2023-09-08 10:05:56 +02:00
Hartley McGuire
bac6d8c079
Fix code blocks using + instead of <tt>
Pluses cannot be used to create code blocks when the content includes a
space.

Found using a regular expression:

```bash
$ rg '#\s[^+]*\+[^+]*\s[^+]*\S\+'
```
2023-08-10 13:05:05 -04:00
Petrik
0e7cb8d327 Add missing headers to Active Storage docs [ci-skip] 2023-04-03 12:29:49 +02:00
Shouichi Kamiya
98abeea7b6 Allow destroying active storage variant
Background:

When creating active storage variants, `ActiveStorage::VariantRecord` is
inserted, then a file is uploaded. Because upload can be failed, the
file can be missing even though `ActiveStorage::VariantRecord` exists.

When a file is missing, we need to delete the corresponding
`ActiveStorage::VariantRecord` but there's no API to delete just one
variant e.g., `blob.variant(resize_to_limit: [100, 100]).destroy`.

Co-authored-by: Yuichiro NAKAGAWA <ii.hsif.drows@gmail.com>
Co-authored-by: Ryohei UEDA <ueda@anipos.co.jp>
2023-02-08 18:36:45 +09:00
Rafael Mendonça França
a17629e393
Fix image_processing link
[ci skip]
2021-12-29 21:36:51 +00:00
Rafael Mendonça França
18707ab17f
Standardize nodoc comments 2021-07-29 21:18:07 +00:00
Breno Gazzola
9bf523559f Make vips the default variant processor for new apps 2021-07-14 14:26:43 -03:00
Dirkjan Bussink
0523532a3c
Always use OpenSSL constants for Digest operations
As also previously discussed in
https://github.com/rails/rails/pull/40770#issuecomment-748347066, this
moves the usage of Digest constants to always use the OpenSSL version of
those Digest implementations.
2021-06-30 13:57:54 +02:00
Santiago Bartesaghi
65b1e1bb8d Remove already deprecated methods in ActiveStorage 2021-06-27 20:32:05 -03:00
George Claghorn
b80a2bdeb9
Active Storage: upgrade to mini_mime 1.1.0
Fix validating uppercase variant formats. Closes #41796.
2021-04-04 22:44:02 -04:00
George Claghorn
b6d86add73 Remove unused require
Follows up on a185ff8.
2020-09-23 14:39:52 -04:00
George Claghorn
a185ff86c0
Set default variant format from blob content type 2020-09-22 13:03:53 -04:00
George Claghorn
b221a4dc43
Proxying: sanitize Content-Type and Content-Disposition
Prevent XSS where unsafe content is served inline on the application origin.

Follows up on #34477. References 06ab7b2 and d40284b.
2020-08-31 11:24:13 -04:00
George Claghorn
57d926a78a Fix unintentional method redefinitions
References dfb5a82.
2020-05-14 09:46:16 -04:00
Jonathan Fleckenstein
dfb5a82b25
Active Storage: allow serving files by proxying 2020-05-11 16:21:58 -04:00
JvH
2a12b723bb Add web_image_content_types config option for ActiveStorage
Add `config.active_storage.web_image_content_types` to allow applications
to add content types (like `image/webp`) in which variants can be processed,
instead of letting those images be converted to the fallback PNG format.
2020-04-21 14:00:41 -04:00
Philipp Defner
9dbe7fdb1e
Fix URL after repo got moved to libvips Github organization 2020-02-13 21:25:36 +01:00
Peter Zhu
235f2636cd Deprecate service_url in favour of url 2019-12-02 14:59:03 -05:00
Kyle Ribordy
698e9ce0ff Set Content-Type on variant uploads 2019-10-01 20:51:13 -04:00
George Claghorn
5f50f4d63b Inline anemic methods 2019-05-15 15:53:43 -04:00
George Claghorn
c1e949e9e6 Prefer ImageProcessing's resize_to_limit macro over resize_to_fit
Don't upsize images smaller than the specified dimensions.
2019-01-24 11:46:42 -05:00
George Claghorn
697f4a93ad Extract transformers 2018-08-10 12:42:14 -04:00
George Claghorn
10129fbf57 DRY up web image checks in ActiveStorage::Variant 2018-08-09 19:53:12 -04:00
George Claghorn
b21f50d8ae Permit configuring the default service URL expiry 2018-06-21 11:06:32 -04:00
lucfranken
8cc79f502e
Active storage: Image variant options not correct
### Steps to reproduce

Using Rails 5.2.0

When following this example:

http://api.rubyonrails.org/classes/ActiveStorage/Variant.html

`avatar.variant(resize: "100x100", monochrome: true, flip: "-90")`

### Expected behavior

Image should be rendered as flipped.

### Actual behavior

I get an error:

> failed with error: gm mogrify: Unrecognized option (-90).

### Fix:

According to: https://github.com/minimagick/minimagick the option should be called rotate:

`avatar.variant(resize: "100x100", monochrome: true, rotate: "-90")`

So **flip** changed to **rotate**.

### System configuration
**Rails version**: 5.2.0

**Ruby version**: ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin17]
2018-05-17 12:49:11 +02:00
George Claghorn
ee21b7c2eb Add ActiveStorage::Blob#open
[David Robertson & George Claghorn]
2018-05-16 22:12:31 -04:00
Janko Marohnić
eef0bd0c0a
Recommend using :resize_to_fit after all 2018-04-23 21:04:35 +02:00
Janko Marohnić
e40091648b
Remove warning that image will be loaded into memory
This is not true anymore, the image will be downloaded into a temporary
file in a streaming fashion.
2018-04-23 12:24:26 +02:00
Janko Marohnić
7fc8b6d82c
Show ImageProcessing macros in a dedicated example 2018-04-23 12:21:42 +02:00
Janko Marohnić
0d811fd482
Ensure result file is deleted on uploading errors 2018-04-22 23:43:11 +02:00
Janko Marohnić
f01e249890
Rename ActiveStorage.processor to .variant_processor 2018-04-22 23:40:42 +02:00
Janko Marohnić
ca12968587
Use ImageProcessing gem for ActiveStorage variants
ImageProcessing gem is a wrapper around MiniMagick and ruby-vips, and
implements an interface for common image resizing and processing. This
is the canonical image processing gem recommended in [Shrine], and
that's where it developed from. The initial implementation was extracted
from Refile, which also implements on-the-fly transformations.

Some features that ImageProcessing gem adds on top of MiniMagick:

  * resizing macros
    - #resize_to_limit
    - #resize_to_fit
    - #resize_to_fill
    - #resize_and_pad
  * automatic orientation
  * automatic thumbnail sharpening
  * avoids the complex and inefficient MiniMagick::Image class
  * will use "magick" instead of "convert" on ImageMagick 7

However, the biggest feature of the ImageProcessing gem is that it has
an alternative implementation that uses libvips. Libvips is an
alternative to ImageMagick that can process images very rapidly (we've
seen up 10x faster than ImageMagick).

What's great is that the ImageProcessing gem provides the same interface
for both implementations. The macros are named the same, and the libvips
implementation does auto orientation and thumbnail sharpening as well;
only the operations/options specific to ImageMagick/libvips differ. The
integration provided by this PR should work for both implementations.

The plan is to introduce the ImageProcessing backend in Rails 6.0 as the
default backend and deprecate the MiniMagick backend, then in Rails 6.1
remove the MiniMagick backend.
2018-04-18 17:46:25 +02:00
dixpac
c520417ad1 Fix leftover references to VariantsController [ci skip]
VariantsController has been merged to RepresentationsController, this
PR fixes outdated references to VariantsController in ActiveStorage documentation.
2018-04-08 14:07:21 +02:00
George Claghorn
3915a470d2 Support varying ICO files
Closes #32096.
2018-02-24 15:27:57 -05:00
Yoshiyuki Hirano
d8c49d88f6 [ci skip] Remove needless from doc for ActiveStorage::Variant 2017-12-22 05:04:25 +09:00
George Claghorn
2df99f8bc5 Delete MiniMagick tempfile when transformation fails 2017-12-18 22:01:48 -05:00
George Claghorn
a6eb2a27c3 Ensure MiniMagick tempfiles are properly unlinked after image transformation 2017-12-18 13:14:26 -05:00
George Claghorn
95117a2ce2 Convert non-web image (e.g. PSD) variants to PNG 2017-12-18 07:49:24 -05:00
George Claghorn
29da7d1ff5 Clarify comment [ci skip] 2017-10-13 07:52:39 -04:00
George Claghorn
445c682a84 Introduce ActiveStorage::Blob#representation 2017-10-12 11:47:21 -04:00
khall
ead60686e8 Replace variation key use with SHA256 of key to prevent long filenames
If a variant has a large set of options associated with it, the generated
filename will be too long, causing Errno::ENAMETOOLONG to be raised. This
change replaces those potentially long filenames with a much more compact
SHA256 hash. Fixes #30662.
2017-10-05 20:57:33 -07:00
George Claghorn
d30586211b Preview PDFs and videos 2017-09-28 16:43:37 -04:00
Yoshiyuki Hirano
7ba922bb48 Fix link in doc for active storage [ci skip] 2017-08-25 22:44:46 +09:00
Xavier Noria
d8bf5d73c3 restores some double newlines deleted in ae87217
These were intentional, see

https://github.com/rails/rails/pull/30061#issuecomment-320068368
2017-08-15 22:01:24 +02:00
Xavier Noria
ae87217382 minor tweaks in Active Storage after a walkthrough 2017-08-15 18:50:46 +02:00
Koichi ITO
d02844f249 Use frozen string literal in Active Storage 2017-08-12 21:43:42 +09:00
Koichi ITO
d90f261562 Fix formatting of Active Storage docs [ci skip]
Follow up of #30188.
2017-08-11 13:15:23 +09:00
qsona
7cfa80f812 Fix a typo 2017-08-10 12:11:28 +09:00
David Heinemeier Hansson
13882d0067 Remove circular dependency 2017-08-01 17:12:57 -05:00