shrine 2.3.0 → 2.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ed4ba1e9f5dafe48af21c7f80039ca3d0014e600
4
- data.tar.gz: 2f8f7903b3032d8ef43508a0e7259ab5deaedb25
3
+ metadata.gz: 27f5213f9cac952b0947848a6f9b518ca5ed6705
4
+ data.tar.gz: d343abd428ddc64dec6d9a049509acdeebe90692
5
5
  SHA512:
6
- metadata.gz: 3d9200a6bfc5fe5705272a4d01a2e62a7146e869c53ede22534ec9043fa87e7c9566b58b5a7cf10f9667de47a9e91d468e34dae146b8cc8526f94cdcbe0f4404
7
- data.tar.gz: 3c9673213a120a2d8427a9bee3280bccb97819154f1bd5bc7bc548f3a70274891133c4c86151b52bd8f94bdc158a4f8be84adf364edd2fd3488f7df98b75d5ef
6
+ metadata.gz: f33bf01e38fa6e854467121d0d92f640491977d234a1201c7c4187503e889965ba797e54f3d05d561e8862bbe32c82edf2cbda6e63ab1557f222ce225613322a
7
+ data.tar.gz: 32351b7cb1fb3afd6bf31d206096fe034b038ed518950dbf82ca95cca8e4c718168ff4c50a5467c671e1d3a04ef7469e15c20ff61724edae416ebe31c7ffa0c3
data/README.md CHANGED
@@ -602,7 +602,7 @@ demo apps which implement multiple uploads directly to S3.
602
602
  ## Backgrounding
603
603
 
604
604
  Shrine is the first file upload library designed for backgrounding support.
605
- Moving phases of managing attachments to background jobs is essential for
605
+ Moving phases of managing file attachments to background jobs is essential for
606
606
  scaling and good user experience, and Shrine provides a `backgrounding` plugin
607
607
  which makes it really easy to plug in your favourite backgrounding library:
608
608
 
@@ -630,7 +630,7 @@ end
630
630
 
631
631
  The above puts all promoting (uploading cached file to permanent storage) and
632
632
  deleting of files into a background Sidekiq job. Obviously instead of Sidekiq
633
- you can use any other backgrounding library.
633
+ you can use [any other backgrounding library][backgrounding libraries].
634
634
 
635
635
  The main advantages of Shrine's backgrounding support over other file upload
636
636
  libraries are:
@@ -720,3 +720,4 @@ The gem is available as open source under the terms of the [MIT License].
720
720
  [rails_demo]: https://github.com/erikdahlstrand/shrine-rails-example
721
721
  [Direct Uploads to S3]: http://shrinerb.com/rdoc/files/doc/direct_s3_md.html
722
722
  [website]: http://shrinerb.com
723
+ [backgrounding libraries]: https://github.com/janko-m/shrine/wiki/Backgrounding-libraries
@@ -10,12 +10,12 @@ methods:
10
10
  class Shrine
11
11
  module Storage
12
12
  class MyStorage
13
- def upload(io, id, **options)
14
- # uploads `io` to the location `id`
13
+ def upload(io, id, shrine_metadata: {}, **upload_options)
14
+ # uploads `io` to the location `id`, can accept upload options
15
15
  end
16
16
 
17
17
  def url(id, **options)
18
- # URL to the remote file, accepts options for customizing the URL
18
+ # returns URL to the remote file, accepts options for customizing the URL
19
19
  end
20
20
 
21
21
  def open(id)
@@ -64,8 +64,8 @@ end
64
64
  ## Download
65
65
 
66
66
  Shrine automatically downloads the file to a Tempfile using `#open`. However,
67
- if you would like to implement your own downloading, you can define `#download`
68
- and Shrine will use that instead:
67
+ if you would like to do custom downloading, you can define `#download` and
68
+ Shrine will use that instead:
69
69
 
70
70
  ```rb
71
71
  class Shrine
@@ -83,10 +83,15 @@ class Shrine
83
83
  end
84
84
  ```
85
85
 
86
- ## Update
86
+ ## Presign
87
87
 
88
- If your storage supports updating data of existing files (e.g. some metadata),
89
- the convention is to create an `#update` method:
88
+ If the storage service supports direct uploads, and requires fetching
89
+ additional information from the server, you can implement a `#presign` method,
90
+ which will be used by the `direct_upload` plugin. The method should return an
91
+ object which responds to
92
+
93
+ * `#url` – returns the URL to which the file should be uploaded to
94
+ * `#fields` – returns a hash of request parameters for the upload
90
95
 
91
96
  ```rb
92
97
  class Shrine
@@ -94,8 +99,8 @@ class Shrine
94
99
  class MyStorage
95
100
  # ...
96
101
 
97
- def update(id, options = {})
98
- # update data of the file
102
+ def presign(id, **options)
103
+ # returns an object which responds to #url and #presign
99
104
  end
100
105
 
101
106
  # ...
@@ -157,6 +162,7 @@ While this method is not used by Shrine, it is good to give users the
157
162
  possibility to delete all files in a storage, and the conventional name for
158
163
  this method is `#clear!`:
159
164
 
165
+ ```rb
160
166
  class Shrine
161
167
  module Strorage
162
168
  class MyStorage
@@ -170,6 +176,28 @@ class Shrine
170
176
  end
171
177
  end
172
178
  end
179
+ ```
180
+
181
+ ## Update
182
+
183
+ If your storage supports updating data of existing files (e.g. some metadata),
184
+ the convention is to create an `#update` method:
185
+
186
+ ```rb
187
+ class Shrine
188
+ module Storage
189
+ class MyStorage
190
+ # ...
191
+
192
+ def update(id, options = {})
193
+ # update data of the file
194
+ end
195
+
196
+ # ...
197
+ end
198
+ end
199
+ end
200
+ ```
173
201
 
174
202
  ## Linter
175
203
 
@@ -3,21 +3,21 @@
3
3
  Shrine gives you the ability to upload files directly to Amazon S3, which is
4
4
  beneficial for several use cases:
5
5
 
6
- * accepting uploads is resource-intensive for the server, and delegating it to
7
- an external service makes scaling easier
6
+ * Accepting uploads is resource-intensive for the server, and delegating it to
7
+ an external service makes scaling easier.
8
8
 
9
- * if both temporary and permanent storage are S3, promoting an S3 file to
9
+ * If both temporary and permanent storage are S3, promoting an S3 file to
10
10
  permanent storage will simply issue an S3 copy request, without any
11
- downloading and reuploading
11
+ downloading and reuploading.
12
12
 
13
- * with multiple servers it's generally not possible to cache files to the disk,
14
- unless you're using a distibuted filesystem that's shared between servers
13
+ * With multiple servers it's generally not possible to cache files to the disk,
14
+ unless you're using a distibuted filesystem that's shared between servers.
15
15
 
16
16
  * Heroku restricts file uploads to disk, allowing you to save files only in
17
- the temporary folder, which gets wiped out between deploys
17
+ the temporary folder, which gets wiped out between deploys.
18
18
 
19
19
  * Heroku has a 30-second request limit, so if the client has a slow connection
20
- and/or your files are larger, uploads to your app can easily hit that limit
20
+ and/or your files are larger, uploads to your app can easily hit that limit.
21
21
 
22
22
  You can start by setting both temporary and permanent storage to S3 with
23
23
  different prefixes (or even buckets):
@@ -28,7 +28,12 @@ gem "aws-sdk", "~> 2.1"
28
28
  ```rb
29
29
  require "shrine/storage/s3"
30
30
 
31
- s3_options = {access_key_id: "...", secret_access_key: "...", region: "..."}
31
+ s3_options = {
32
+ access_key_id: "abc",
33
+ secret_access_key: "123",
34
+ region: "my-region",
35
+ bucket: "my-bucket",
36
+ }
32
37
 
33
38
  Shrine.storages = {
34
39
  cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
@@ -227,4 +232,5 @@ end
227
232
  [demo app]: https://github.com/janko-m/shrine/tree/master/demo
228
233
  [Dropzone]: https://github.com/enyo/dropzone
229
234
  [jQuery-File-Upload]: https://github.com/blueimp/jQuery-File-Upload
235
+ [FineUploader]: https://github.com/FineUploader/fine-uploader
230
236
  [Amazon S3 Data Consistency Model]: http://docs.aws.amazon.com/AmazonS3/latest/dev/Introduction.html#ConsistencyMode
@@ -0,0 +1,73 @@
1
+ class Shrine
2
+ module Plugins
3
+ # The `concatenation` plugin allows you to assign to the attacher a
4
+ # cached file which is composed of multiple uploaded parts. The plugin
5
+ # will then call `#concat` on the storage, which is expected to
6
+ # concatenate the given parts into a single file. The assigned
7
+ # attachment will then be a complete cached file.
8
+ #
9
+ # plugin :concatenation
10
+ #
11
+ # The plugin expects to receive the cached file in the standard JSON
12
+ # format, with an additional `"parts"` key which is the array of
13
+ # uploaded parts:
14
+ #
15
+ # {
16
+ # "id": "lsdg94l31.jpg",
17
+ # "storage": "cache",
18
+ # "parts": [
19
+ # {"id": "aaa", "storage": "cache", "metadata": {}},
20
+ # {"id": "bbb", "storage": "cache", "metadata": {}},
21
+ # # ...
22
+ # ],
23
+ # "metadata": {
24
+ # # ...
25
+ # }
26
+ # }
27
+ #
28
+ # The `"metadata"` field of individual parts should contain information
29
+ # that your storage needs to perform concatenation, refer to the
30
+ # documentation of your storage.
31
+ #
32
+ # You can also pass additional storage-specific concatenation options:
33
+ #
34
+ # plugin :concatenation, options: {use_accelerate_endpoint: true}
35
+ #
36
+ # plugin :concatenation, options: ->(io, context) do
37
+ # {use_accelerate_endpoint: true} unless context[:record].guest?
38
+ # end
39
+ module Concatenation
40
+ def self.configure(uploader, opts = {})
41
+ uploader.opts[:concatenation_options] = opts.fetch(:options, uploader.opts.fetch(:options, {}))
42
+ end
43
+
44
+ module AttacherMethods
45
+ def assign(value)
46
+ if value.is_a?(String) && !value.empty?
47
+ data = JSON.parse(value)
48
+
49
+ if data.key?("parts")
50
+ parts = data["parts"].map { |part_data| uploaded_file(part_data) }
51
+ location = data["id"]
52
+ metadata = data["metadata"]
53
+
54
+ options = shrine_class.opts[:concatenation_options]
55
+ options = options.call(uploaded_file(data), context) if options.respond_to?(:call)
56
+ options ||= {}
57
+
58
+ cache.storage.concat(parts, location, shrine_metadata: metadata, **options)
59
+
60
+ data.delete("parts")
61
+
62
+ assign(data.to_json)
63
+ else
64
+ super
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+
71
+ register_plugin(:concatenation, Concatenation)
72
+ end
73
+ end
@@ -85,10 +85,14 @@ class Shrine
85
85
  # can use this option to set a CDN host (e.g. `//abc123.cloudfront.net`).
86
86
  #
87
87
  # :permissions
88
- # : Changes the UNIX permissions of created files (default is 0644).
88
+ # : The UNIX permissions applied to created files. Can be set to `nil`,
89
+ # in which case the default permissions will be applied. Defaults to
90
+ # `0644`.
89
91
  #
90
92
  # :directory_permissions
91
- # : Changes the UNIX permissions of created directories (default is 0755).
93
+ # : The UNIX permissions applied to created directories. Can be set to
94
+ # `nil`, in which case the default permissions will be applied. Defaults
95
+ # to `0755`.
92
96
  #
93
97
  # :clean
94
98
  # : By default empty folders inside the directory are automatically
@@ -107,8 +111,10 @@ class Shrine
107
111
  @directory_permissions = directory_permissions
108
112
  @clean = clean
109
113
 
110
- @directory.mkpath
111
- @directory.chmod(directory_permissions) if directory_permissions
114
+ unless @directory.exist?
115
+ @directory.mkpath
116
+ @directory.chmod(directory_permissions) if directory_permissions
117
+ end
112
118
  end
113
119
 
114
120
  # Copies the file into the given location.
@@ -35,7 +35,7 @@ class Shrine
35
35
  def call(io_factory = default_io_factory)
36
36
  storage.upload(io_factory.call, id = "foo", {})
37
37
 
38
- lint_download(id)
38
+ lint_download(id) if storage.respond_to?(:download)
39
39
  lint_open(id)
40
40
  lint_exists(id)
41
41
  lint_url(id)
@@ -6,7 +6,7 @@ class Shrine
6
6
  module VERSION
7
7
  MAJOR = 2
8
8
  MINOR = 3
9
- TINY = 0
9
+ TINY = 1
10
10
  PRE = nil
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shrine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janko Marohnić
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-27 00:00:00.000000000 Z
11
+ date: 2016-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: down
@@ -311,6 +311,7 @@ files:
311
311
  - lib/shrine/plugins/backgrounding.rb
312
312
  - lib/shrine/plugins/backup.rb
313
313
  - lib/shrine/plugins/cached_attachment_data.rb
314
+ - lib/shrine/plugins/concatenation.rb
314
315
  - lib/shrine/plugins/copy.rb
315
316
  - lib/shrine/plugins/data_uri.rb
316
317
  - lib/shrine/plugins/default_storage.rb