shrine 3.0.0 → 3.0.1
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 +41 -33
- data/README.md +85 -0
- data/doc/advantages.md +3 -3
- data/doc/attacher.md +14 -15
- data/doc/carrierwave.md +4 -4
- data/doc/design.md +2 -2
- data/doc/external/articles.md +1 -0
- data/doc/external/extensions.md +1 -0
- data/doc/getting_started.md +8 -7
- data/doc/paperclip.md +5 -5
- data/doc/plugins/activerecord.md +4 -4
- data/doc/plugins/derivatives.md +4 -4
- data/doc/plugins/entity.md +3 -3
- data/doc/plugins/model.md +4 -4
- data/doc/plugins/sequel.md +4 -4
- data/doc/plugins/versions.md +4 -4
- data/doc/release_notes/3.0.0.md +274 -257
- data/doc/release_notes/3.0.1.md +18 -0
- data/doc/upgrading_to_3.md +19 -1
- data/lib/shrine/attacher.rb +1 -1
- data/lib/shrine/plugins/derivatives.rb +3 -3
- data/lib/shrine/plugins/metadata_attributes.rb +1 -1
- data/lib/shrine/uploaded_file.rb +5 -0
- data/lib/shrine/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b327565465d4140206d1f88433647e7959b6c56ecbdea7d433f1aa5eb01825d
|
4
|
+
data.tar.gz: c19fb7f15299b1d061325f8f83e790f44481456fbc9730d4a909923193dde1a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 897bbe8787b3a1f7e59db3e6beebbc91b32ec5e4c19cd832029e05205425c12d837bf8475f21949c23a6c805504da45a0937de0d3dc9f50d3d35921b5f6a7901
|
7
|
+
data.tar.gz: 995b0ada0e5bdb2c4e198304d913f6cfe22d8814328d58bf559490ea572ac3d5555f3eb15fce898ae423ff54f76ba3bcbbeb7f6e05470ddca8acee37ee675455
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
## 3.0.
|
1
|
+
## 3.0.1 (2019-10-17) [[release notes]](https://shrinerb.com/docs/release_notes/3.0.1)
|
2
|
+
|
3
|
+
* `metadata_attributes` – Fix exception being raised when there is no attached file (@janko)
|
4
|
+
|
5
|
+
* `core` – Simplify `UploadedFile#inspect` output (@janko)
|
6
|
+
|
7
|
+
## 3.0.0 (2019-10-14) [[release notes]](https://shrinerb.com/docs/release_notes/3.0.0)
|
2
8
|
|
3
9
|
* `derivation_endpoint` – Pass `action: :derivation` when uploading derivation results (@janko)
|
4
10
|
|
@@ -230,6 +236,8 @@
|
|
230
236
|
|
231
237
|
* `core` – Add `Attacher#data` and `Attacher.from_data` for dumping to and loading from a Hash (@janko)
|
232
238
|
|
239
|
+
* `core` – Change `Attacher#assign` to raise exception when non-cached file is assigned (@janko)
|
240
|
+
|
233
241
|
* `core` – Enable `Attacher#assign` to accept cached file data as a Hash (@janko)
|
234
242
|
|
235
243
|
* `core` – Add `Attacher#file` alias for `Attacher#get` (@janko)
|
@@ -356,7 +364,7 @@
|
|
356
364
|
|
357
365
|
* `s3` – Drop support for `aws-sdk` 2.x (@janko)
|
358
366
|
|
359
|
-
## 2.19.0 (2019-07-18)
|
367
|
+
## 2.19.0 (2019-07-18) [[release notes]](https://shrinerb.com/docs/release_notes/2.19.0)
|
360
368
|
|
361
369
|
* `pretty_location` – Allow specifying a different identifier from `id` (@00dav00)
|
362
370
|
|
@@ -412,7 +420,7 @@
|
|
412
420
|
|
413
421
|
* `core` – Allow registering storage objects under string keys (@janko)
|
414
422
|
|
415
|
-
## 2.18.0 (2019-06-24)
|
423
|
+
## 2.18.0 (2019-06-24) [[release notes]](https://shrinerb.com/docs/release_notes/2.18.0)
|
416
424
|
|
417
425
|
* `core` – Add `Shrine.upload` method as a shorthand for `Shrine.new(...).upload(...)` (@janko)
|
418
426
|
|
@@ -436,7 +444,7 @@
|
|
436
444
|
|
437
445
|
* `parsed_json` – Fix overriden `Attacher#assign` not accepting second argument (@janko)
|
438
446
|
|
439
|
-
## 2.17.0 (2019-05-06)
|
447
|
+
## 2.17.0 (2019-05-06) [[release notes]](https://shrinerb.com/docs/release_notes/2.17.0)
|
440
448
|
|
441
449
|
* `data_uri` – Add `Attacher#assign_data_uri` which accepts additional `Shrine#upload` options (@janko)
|
442
450
|
|
@@ -486,7 +494,7 @@
|
|
486
494
|
|
487
495
|
* `parsed_json` – Accepts hashes with symbols keys (@aglushkov)
|
488
496
|
|
489
|
-
## 2.16.0 (2019-02-18)
|
497
|
+
## 2.16.0 (2019-02-18) [[release notes]](https://shrinerb.com/docs/release_notes/2.16.0)
|
490
498
|
|
491
499
|
* `derivation_endpoint` – Add `:upload_open_options` for download option for derivation result (@janko)
|
492
500
|
|
@@ -512,7 +520,7 @@
|
|
512
520
|
|
513
521
|
* Fix `store_dimensions` plugin making second argument in `Shrine#extract_metadata` mandatory (@jrochkind)
|
514
522
|
|
515
|
-
## 2.15.0 (2019-02-08)
|
523
|
+
## 2.15.0 (2019-02-08) [[release notes]](https://shrinerb.com/docs/release_notes/2.15.0)
|
516
524
|
|
517
525
|
* Add `derivation_endpoint` plugin for processing uploaded files on-the-fly (@janko)
|
518
526
|
|
@@ -522,7 +530,7 @@
|
|
522
530
|
|
523
531
|
* Yield a new File object on `Shrine.with_file` when `tempfile` plugin is loaded (@janko)
|
524
532
|
|
525
|
-
## 2.14.0 (2018-12-27)
|
533
|
+
## 2.14.0 (2018-12-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.14.0)
|
526
534
|
|
527
535
|
* Add `tempfile` plugin for easier reusing of the same uploaded file copy on disk (@janko)
|
528
536
|
|
@@ -592,7 +600,7 @@
|
|
592
600
|
|
593
601
|
* Use a guard raise cause for `bucket` argument in S3 for an appropriate error message (@ardecvz)
|
594
602
|
|
595
|
-
## 2.13.0 (2018-11-04)
|
603
|
+
## 2.13.0 (2018-11-04) [[release notes]](https://shrinerb.com/docs/release_notes/2.13.0)
|
596
604
|
|
597
605
|
* Specify UTF-8 charset in `Content-Type` response header in `presign_endpoint` plugin (@janko)
|
598
606
|
|
@@ -624,7 +632,7 @@
|
|
624
632
|
|
625
633
|
* In `S3#upload` deprecate using aws-sdk-s3 lower than 1.14 when uploading IO objects of unknown size (@janko)
|
626
634
|
|
627
|
-
## 2.12.0 (2018-08-22)
|
635
|
+
## 2.12.0 (2018-08-22) [[release notes]](https://shrinerb.com/docs/release_notes/2.12.0)
|
628
636
|
|
629
637
|
* Ignore nil values when assigning files from a remote URL (@janko)
|
630
638
|
|
@@ -652,7 +660,7 @@
|
|
652
660
|
|
653
661
|
* Make `UploadedFile#open` always open a new IO object and close the previous one (@janko)
|
654
662
|
|
655
|
-
## 2.11.0 (2018-04-28)
|
663
|
+
## 2.11.0 (2018-04-28) [[release notes]](https://shrinerb.com/docs/release_notes/2.11.0)
|
656
664
|
|
657
665
|
* Add `Shrine.with_file` for temporarily converting an IO-like object into a file (@janko)
|
658
666
|
|
@@ -680,7 +688,7 @@
|
|
680
688
|
|
681
689
|
* Deprecate `direct_upload` plugin in favor of `upload_endpoint` and `presign_endpoint` plugins (@janko)
|
682
690
|
|
683
|
-
## 2.10.0 (2018-03-28)
|
691
|
+
## 2.10.0 (2018-03-28) [[release notes]](https://shrinerb.com/docs/release_notes/2.10.0)
|
684
692
|
|
685
693
|
* Add `:fastimage` analyzer to `determine_mime_type` plugin (@mokolabs)
|
686
694
|
|
@@ -702,7 +710,7 @@
|
|
702
710
|
|
703
711
|
* Inherit the logger on subclassing `Shrine` and make it shared across subclasses (@hmistry)
|
704
712
|
|
705
|
-
## 2.9.0 (2018-01-27)
|
713
|
+
## 2.9.0 (2018-01-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.9.0)
|
706
714
|
|
707
715
|
* Support arrays of files in `versions` plugin (@janko)
|
708
716
|
|
@@ -726,7 +734,7 @@
|
|
726
734
|
|
727
735
|
* Allow passing options to `Model#<attachment>_attacher` for overriding `Attacher` options (@janko)
|
728
736
|
|
729
|
-
## 2.8.0 (2017-10-11)
|
737
|
+
## 2.8.0 (2017-10-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.8.0)
|
730
738
|
|
731
739
|
* Expand relative directory paths when initializing `Storage::FileSystem` (@janko)
|
732
740
|
|
@@ -756,7 +764,7 @@
|
|
756
764
|
|
757
765
|
* Update `direct_upload` plugin to support Roda 3 (@janko)
|
758
766
|
|
759
|
-
## 2.7.0 (2017-09-11)
|
767
|
+
## 2.7.0 (2017-09-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.7.0)
|
760
768
|
|
761
769
|
* Deprecate the `Shrine::DownloadEndpoint` constant over `Shrine.download_endpoint` (@janko)
|
762
770
|
|
@@ -824,11 +832,11 @@
|
|
824
832
|
|
825
833
|
* Don't add a newline at the end of the base64-formatted signature (@janko)
|
826
834
|
|
827
|
-
## 2.6.1 (2017-04-12)
|
835
|
+
## 2.6.1 (2017-04-12) [[release notes]](https://shrinerb.com/docs/release_notes/2.6.1)
|
828
836
|
|
829
837
|
* Fix `download_endpoint` returning incorrect reponse body in some cases (@janko)
|
830
838
|
|
831
|
-
## 2.6.0 (2017-04-04)
|
839
|
+
## 2.6.0 (2017-04-04) [[release notes]](https://shrinerb.com/docs/release_notes/2.6.0)
|
832
840
|
|
833
841
|
* Make `Shrine::Storage::FileSystem#path` public which returns path to the file as a `Pathname` object (@janko)
|
834
842
|
|
@@ -900,7 +908,7 @@
|
|
900
908
|
|
901
909
|
* Raise `Shrine::Error` when `Shrine#generate_location` returns nil (@janko)
|
902
910
|
|
903
|
-
## 2.5.0 (2016-11-11)
|
911
|
+
## 2.5.0 (2016-11-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.5.0)
|
904
912
|
|
905
913
|
* Add `Attacher.default_url` as the idiomatic way of declaring default URLs (@janko)
|
906
914
|
|
@@ -926,7 +934,7 @@
|
|
926
934
|
|
927
935
|
* Make it possible to extract multiple metadata values at once with the `add_metadata` plugin (@janko)
|
928
936
|
|
929
|
-
## 2.4.1 (2016-10-17)
|
937
|
+
## 2.4.1 (2016-10-17) [[release notes]](https://shrinerb.com/docs/release_notes/2.4.1)
|
930
938
|
|
931
939
|
* Move back JSON serialization from `Attacher#write` to `Attacher#_set` (@janko)
|
932
940
|
|
@@ -936,7 +944,7 @@
|
|
936
944
|
|
937
945
|
* In `UploadedFile#download` use extension from `#original_filename` if `#id` doesn't have it (@janko)
|
938
946
|
|
939
|
-
## 2.4.0 (2016-10-11)
|
947
|
+
## 2.4.0 (2016-10-11) [[release notes]](https://shrinerb.com/docs/release_notes/2.4.0)
|
940
948
|
|
941
949
|
* Add `#convert_before_write` and `#convert_after_read` on the Attacher for data attribute conversion (@janko)
|
942
950
|
|
@@ -972,11 +980,11 @@
|
|
972
980
|
|
973
981
|
* Override `#to_s` in `Shrine::Attachment` for better introspection with `puts` (@janko)
|
974
982
|
|
975
|
-
## 2.3.1 (2016-09-01)
|
983
|
+
## 2.3.1 (2016-09-01) [[release notes]](https://shrinerb.com/docs/release_notes/2.3.1)
|
976
984
|
|
977
985
|
* Don't change permissions of existing directories in FileSystem storage (@janko)
|
978
986
|
|
979
|
-
## 2.3.0 (2016-08-27)
|
987
|
+
## 2.3.0 (2016-08-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.3.0)
|
980
988
|
|
981
989
|
* Prevent client from caching the presign response in direct_upload plugin (@janko)
|
982
990
|
|
@@ -1002,7 +1010,7 @@
|
|
1002
1010
|
|
1003
1011
|
* Add `:directory_permissions` to `Storage::FileSystem` (@janko)
|
1004
1012
|
|
1005
|
-
## 2.2.0 (2016-07-29)
|
1013
|
+
## 2.2.0 (2016-07-29) [[release notes]](https://shrinerb.com/docs/release_notes/2.2.0)
|
1006
1014
|
|
1007
1015
|
* Soft deprecate `:phase` over `:action` in `context` (@janko)
|
1008
1016
|
|
@@ -1034,11 +1042,11 @@
|
|
1034
1042
|
|
1035
1043
|
* Avoid an additional HEAD request to determine content length in multipart S3 copy (@janko)
|
1036
1044
|
|
1037
|
-
## 2.1.1 (2016-07-14)
|
1045
|
+
## 2.1.1 (2016-07-14) [[release notes]](https://shrinerb.com/docs/release_notes/2.1.1)
|
1038
1046
|
|
1039
1047
|
* Fix `S3#open` throwing a NameError if `net/http` isn't required (@janko)
|
1040
1048
|
|
1041
|
-
## 2.1.0 (2016-06-27)
|
1049
|
+
## 2.1.0 (2016-06-27) [[release notes]](https://shrinerb.com/docs/release_notes/2.1.0)
|
1042
1050
|
|
1043
1051
|
* Remove `:names` from versions plugin, and deprecate generating versions in :cache phase (@janko)
|
1044
1052
|
|
@@ -1054,11 +1062,11 @@
|
|
1054
1062
|
|
1055
1063
|
* Deprecate `#cached_<attachment>_data=` over using `<attachment>` for the hidden field (@janko)
|
1056
1064
|
|
1057
|
-
## 2.0.1 (2016-05-30)
|
1065
|
+
## 2.0.1 (2016-05-30) [[release notes]](https://shrinerb.com/docs/release_notes/2.0.1)
|
1058
1066
|
|
1059
1067
|
* Don't override previously set default_url in versions plugin (@janko)
|
1060
1068
|
|
1061
|
-
## 2.0.0 (2016-05-19)
|
1069
|
+
## 2.0.0 (2016-05-19) [[release notes]](https://shrinerb.com/docs/release_notes/2.0.0)
|
1062
1070
|
|
1063
1071
|
* Include query parameters in CDN-ed S3 URLs, making them work for private objects (@janko)
|
1064
1072
|
|
@@ -1138,17 +1146,17 @@
|
|
1138
1146
|
|
1139
1147
|
* Deprecate loading the backgrounding plugin through the old "background_helpers" alias (@janko)
|
1140
1148
|
|
1141
|
-
## 1.4.2 (2016-04-19)
|
1149
|
+
## 1.4.2 (2016-04-19) [[release notes]](https://shrinerb.com/docs/release_notes/1.4.2)
|
1142
1150
|
|
1143
1151
|
* Removed ActiveRecord's automatic support for optimistic locking as it wasn't stable (@janko)
|
1144
1152
|
|
1145
1153
|
* Fixed record's dataset being modified after promoting preventing further updates with the same instance (@janko)
|
1146
1154
|
|
1147
|
-
## 1.4.1 (2016-04-18)
|
1155
|
+
## 1.4.1 (2016-04-18) [[release notes]](https://shrinerb.com/docs/release_notes/1.4.1)
|
1148
1156
|
|
1149
1157
|
* Bring back triggering callbacks on promote in ORM plugins, and add support for optimistic locking (@janko)
|
1150
1158
|
|
1151
|
-
## 1.4.0 (2016-04-15)
|
1159
|
+
## 1.4.0 (2016-04-15) [[release notes]](https://shrinerb.com/docs/release_notes/1.4.0)
|
1152
1160
|
|
1153
1161
|
* Return "Content-Length" response header in download_endpoint plugin (@janko)
|
1154
1162
|
|
@@ -1204,7 +1212,7 @@
|
|
1204
1212
|
|
1205
1213
|
* Fix keep_files not to spawn a background job when file will not be deleted (@janko)
|
1206
1214
|
|
1207
|
-
## 1.3.0 (2016-03-12)
|
1215
|
+
## 1.3.0 (2016-03-12) [[release notes]](https://shrinerb.com/docs/release_notes/1.3.0)
|
1208
1216
|
|
1209
1217
|
* Add `<attachment>_cached?` and `<attachment>_stored?` to migration_helpers plugin (@janko)
|
1210
1218
|
|
@@ -1246,7 +1254,7 @@
|
|
1246
1254
|
|
1247
1255
|
* Fix `NameError` when silencing "missing record" errors in backgrounding (@janko)
|
1248
1256
|
|
1249
|
-
## 1.2.0 (2016-01-26)
|
1257
|
+
## 1.2.0 (2016-01-26) [[release notes]](https://shrinerb.com/docs/release_notes/1.2.0)
|
1250
1258
|
|
1251
1259
|
* Make `Shrine::Attacher.promote` and `Shrine::Attacher.delete` return the record in backgrounding plugin (@janko)
|
1252
1260
|
|
@@ -1262,7 +1270,7 @@
|
|
1262
1270
|
|
1263
1271
|
* Make custom metadata inherited from uploaded files and make `#extract_metadata` called only on caching (@janko)
|
1264
1272
|
|
1265
|
-
## 1.1.0 (2015-12-26)
|
1273
|
+
## 1.1.0 (2015-12-26) [[release notes]](https://shrinerb.com/docs/release_notes/1.1.0)
|
1266
1274
|
|
1267
1275
|
* Rename the "background_helpers" plugin to "backgrounding" (@janko)
|
1268
1276
|
|
@@ -1332,7 +1340,7 @@
|
|
1332
1340
|
|
1333
1341
|
* Reduce length of URLs generated with pretty_location plugin (@gshaw)
|
1334
1342
|
|
1335
|
-
## 1.0.0 (2015-11-27)
|
1343
|
+
## 1.0.0 (2015-11-27) [[release notes]](https://shrinerb.com/docs/release_notes/1.0.0)
|
1336
1344
|
|
1337
1345
|
* Improve Windows compatibility in the FileSystem storage (@janko)
|
1338
1346
|
|
data/README.md
CHANGED
@@ -23,6 +23,91 @@ Please follow along with the **[Getting Started guide]**.
|
|
23
23
|
| Wiki | [github.com/shrinerb/shrine/wiki](https://github.com/shrinerb/shrine/wiki) |
|
24
24
|
| Help & Discussion | [discourse.shrinerb.com](https://discourse.shrinerb.com) |
|
25
25
|
|
26
|
+
## Setup
|
27
|
+
|
28
|
+
Add the gem to your Gemfile:
|
29
|
+
|
30
|
+
```rb
|
31
|
+
# Gemfile
|
32
|
+
gem "shrine", "~> 3.0"
|
33
|
+
```
|
34
|
+
|
35
|
+
Then add `config/initializers/shrine.rb` which sets up the storage and loads
|
36
|
+
ORM integration:
|
37
|
+
|
38
|
+
```rb
|
39
|
+
require "shrine"
|
40
|
+
require "shrine/storage/file_system"
|
41
|
+
|
42
|
+
Shrine.storages = {
|
43
|
+
cache: Shrine::Storage::FileSystem.new("public", prefix: "uploads/cache"), # temporary
|
44
|
+
store: Shrine::Storage::FileSystem.new("public", prefix: "uploads"), # permanent
|
45
|
+
}
|
46
|
+
|
47
|
+
Shrine.plugin :activerecord # loads Active Record integration
|
48
|
+
Shrine.plugin :cached_attachment_data # enables retaining cached file across form redisplays
|
49
|
+
Shrine.plugin :restore_cached_data # extracts metadata for assigned cached files
|
50
|
+
```
|
51
|
+
|
52
|
+
Next, add the `<name>_data` column to the table you want to attach files to. For
|
53
|
+
an "image" attachment on a `photos` table this would be an `image_data` column:
|
54
|
+
|
55
|
+
```sh
|
56
|
+
$ rails generate migration add_image_data_to_photos image_data:text
|
57
|
+
```
|
58
|
+
|
59
|
+
Now create an uploader class (which you can put in `app/uploaders`) and
|
60
|
+
register the attachment on your model:
|
61
|
+
|
62
|
+
```rb
|
63
|
+
class ImageUploader < Shrine
|
64
|
+
# plugins and uploading logic
|
65
|
+
end
|
66
|
+
```
|
67
|
+
```rb
|
68
|
+
class Photo < ActiveRecord::Base
|
69
|
+
include ImageUploader::Attachment(:image) # adds an `image` virtual attribute
|
70
|
+
end
|
71
|
+
```
|
72
|
+
|
73
|
+
In our views let's now add form fields for our attachment attribute that will
|
74
|
+
allow users to upload files:
|
75
|
+
|
76
|
+
```erb
|
77
|
+
<%= form_for @photo do |f| %>
|
78
|
+
<%= f.hidden_field :image, value: @photo.cached_image_data %>
|
79
|
+
<%= f.file_field :image %>
|
80
|
+
<%= f.submit %>
|
81
|
+
<% end %>
|
82
|
+
```
|
83
|
+
|
84
|
+
When the form is submitted, in your controller you can assign the file from
|
85
|
+
request params to the attachment attribute on the model:
|
86
|
+
|
87
|
+
```rb
|
88
|
+
class PhotosController < ApplicationController
|
89
|
+
def create
|
90
|
+
Photo.create(photo_params) # attaches the uploaded file
|
91
|
+
# ...
|
92
|
+
end
|
93
|
+
|
94
|
+
private
|
95
|
+
|
96
|
+
def photo_params
|
97
|
+
params.require(:photo).permit(:image)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
Once a file is uploaded and attached to the record, you can retrieve the file
|
103
|
+
URL and display it on the page:
|
104
|
+
|
105
|
+
```erb
|
106
|
+
<%= image_tag @photo.image_url %>
|
107
|
+
```
|
108
|
+
|
109
|
+
See the **[Getting Started guide]** for further documentation.
|
110
|
+
|
26
111
|
## Inspiration
|
27
112
|
|
28
113
|
Shrine was heavily inspired by [Refile] and [Roda]. From Refile it borrows the
|
data/doc/advantages.md
CHANGED
@@ -276,9 +276,9 @@ end
|
|
276
276
|
```rb
|
277
277
|
movie.video_derivatives! # create derivatives
|
278
278
|
|
279
|
-
movie.video #=> #<Shrine::UploadedFile
|
280
|
-
movie.video(:transcoded) #=> #<Shrine::UploadedFile
|
281
|
-
movie.video(:screenshot) #=> #<Shrine::UploadedFile
|
279
|
+
movie.video #=> #<Shrine::UploadedFile id="5a5cd0.mov" ...>
|
280
|
+
movie.video(:transcoded) #=> #<Shrine::UploadedFile id="7481d6.mp4" ...>
|
281
|
+
movie.video(:screenshot) #=> #<Shrine::UploadedFile id="8f3136.jpg" ...>
|
282
282
|
```
|
283
283
|
|
284
284
|
## Metadata & Validation
|
data/doc/attacher.md
CHANGED
@@ -96,14 +96,14 @@ If given a raw file, it will upload it to temporary storage:
|
|
96
96
|
|
97
97
|
```rb
|
98
98
|
attacher.assign(file)
|
99
|
-
attacher.file #=> #<Shrine::UploadedFile
|
99
|
+
attacher.file #=> #<Shrine::UploadedFile id="asdf.jpg" storage=:cache ...>
|
100
100
|
```
|
101
101
|
|
102
102
|
If given cached file data (JSON or Hash), it will set the cached file:
|
103
103
|
|
104
104
|
```rb
|
105
105
|
attacher.assign('{"id":"asdf.jpg","storage":"cache","metadata":{...}}')
|
106
|
-
attacher.file #=> #<Shrine::UploadedFile
|
106
|
+
attacher.file #=> #<Shrine::UploadedFile id="asdf.jpg" storage=:cache ...>
|
107
107
|
```
|
108
108
|
|
109
109
|
If given an empty string, it will no-op:
|
@@ -143,7 +143,7 @@ The `Attacher#attach` method uploads a given file to permanent storage:
|
|
143
143
|
|
144
144
|
```rb
|
145
145
|
attacher.attach(file)
|
146
|
-
attacher.file #=> #<Shrine::UploadedFile
|
146
|
+
attacher.file #=> #<Shrine::UploadedFile id="asdf.jpg" storage=:store ...>
|
147
147
|
```
|
148
148
|
|
149
149
|
This method is useful when attaching files from scripts, where validation
|
@@ -153,7 +153,7 @@ You can specify a different destination storage with the `:storage` option:
|
|
153
153
|
|
154
154
|
```rb
|
155
155
|
attacher.attach(file, storage: :other_store)
|
156
|
-
attacher.file #=> #<Shrine::UploadedFile
|
156
|
+
attacher.file #=> #<Shrine::UploadedFile id="asdf.jpg" storage=:other_store ...>
|
157
157
|
```
|
158
158
|
|
159
159
|
Any additional options passed to `Attacher#attach`, `Attacher#attach_cached`
|
@@ -171,9 +171,9 @@ If you want to upload a file to without attaching it, you can use
|
|
171
171
|
`Attacher#upload`:
|
172
172
|
|
173
173
|
```rb
|
174
|
-
attacher.upload(file) #=> #<Shrine::UploadedFile
|
175
|
-
attacher.upload(file, :cache) #=> #<Shrine::UploadedFile
|
176
|
-
attacher.upload(file, :other_store) #=> #<Shrine::UploadedFile
|
174
|
+
attacher.upload(file) #=> #<Shrine::UploadedFile storage=:store ...>
|
175
|
+
attacher.upload(file, :cache) #=> #<Shrine::UploadedFile storage=:cache ...>
|
176
|
+
attacher.upload(file, :other_store) #=> #<Shrine::UploadedFile storage=:other_store ...>
|
177
177
|
```
|
178
178
|
|
179
179
|
This is useful if you want to attacher [context](#context) such as `:record`
|
@@ -202,20 +202,19 @@ attacher.changed? #=> true
|
|
202
202
|
You can use `Attacher#change` to attach an `UploadedFile` object as is:
|
203
203
|
|
204
204
|
```rb
|
205
|
-
uploaded_file #=> #<Shrine::UploadedFile
|
205
|
+
uploaded_file #=> #<Shrine::UploadedFile id="foo" ...>
|
206
206
|
attacher.change(uploaded_file)
|
207
|
-
attacher.file #=> #<Shrine::UploadedFile
|
207
|
+
attacher.file #=> #<Shrine::UploadedFile id="foo" ...>
|
208
208
|
attacher.changed? #=> true
|
209
|
-
|
210
209
|
```
|
211
210
|
|
212
211
|
If you want to attach a file without triggering dirty tracking or validation,
|
213
212
|
you can use `Attacher#set`:
|
214
213
|
|
215
214
|
```rb
|
216
|
-
uploaded_file #=> #<Shrine::UploadedFile
|
215
|
+
uploaded_file #=> #<Shrine::UploadedFile id="foo" ...>
|
217
216
|
attacher.set(uploaded_file)
|
218
|
-
attacher.file #=> #<Shrine::UploadedFile
|
217
|
+
attacher.file #=> #<Shrine::UploadedFile id="foo" ...>
|
219
218
|
attacher.changed? #=> false
|
220
219
|
```
|
221
220
|
|
@@ -246,16 +245,16 @@ storage, and in this case uploads it to permanent storage.
|
|
246
245
|
```rb
|
247
246
|
attacher.attach_cached(io)
|
248
247
|
attacher.finalize # uploads attached file to permanent storage
|
249
|
-
attacher.file #=> #<Shrine::UploadedFile
|
248
|
+
attacher.file #=> #<Shrine::UploadedFile storage=:store ...>
|
250
249
|
```
|
251
250
|
|
252
251
|
Internally it calls `Attacher#promote_cached`, which you can call directly if
|
253
252
|
you want to pass any promote options:
|
254
253
|
|
255
254
|
```rb
|
256
|
-
attacher.file #=> #<Shrine::UploadedFile
|
255
|
+
attacher.file #=> #<Shrine::UploadedFile storage=:cache ...>
|
257
256
|
attacher.promote_cached # uploads attached file to permanent storage if new and cached
|
258
|
-
attacher.file #=> #<Shrine::UploadedFile
|
257
|
+
attacher.file #=> #<Shrine::UploadedFile storage=:store ...>
|
259
258
|
```
|
260
259
|
|
261
260
|
You can also call `Attacher#promote` if you want to upload attached file to
|