shrine-cloudinary 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -17
- data/lib/shrine/storage/cloudinary.rb +15 -1
- data/shrine-cloudinary.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7620a61d65d4509c6835b0ab21fc0f47d13cf39a
|
4
|
+
data.tar.gz: d414fe35b912c48e317ed361e5a1a39082c03df7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a181bb8b94a81a687c2ce4bb671799a7445e39565d558f2538d640d841dff5f61ccfbd883a223ea428d076e873587492e57ef40a997c94f73a057d74a09cc87
|
7
|
+
data.tar.gz: f81035721ad1988bbb369966a2effa215d79cf451165c90eabe5773077335493e0a15f4a90901506d90dcab8db764b97c099aaedd0a60efbbda3b135afacc191
|
data/README.md
CHANGED
@@ -2,9 +2,8 @@
|
|
2
2
|
|
3
3
|
Provides [Cloudinary] storage for [Shrine].
|
4
4
|
|
5
|
-
Cloudinary provides storage
|
6
|
-
|
7
|
-
types of files.
|
5
|
+
Cloudinary provides storage and advanced processing for images and videos, both
|
6
|
+
on-demand and on upload.
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
@@ -14,32 +13,62 @@ gem "shrine-cloudinary"
|
|
14
13
|
|
15
14
|
## Usage
|
16
15
|
|
17
|
-
|
16
|
+
You'll typically want to upload photos directly to Cloudinary, so your setup
|
17
|
+
might look like this:
|
18
18
|
|
19
19
|
```rb
|
20
20
|
require "cloudinary"
|
21
|
+
require "shrine/storage/cloudinary"
|
21
22
|
|
22
23
|
Cloudinary.config(
|
23
24
|
cloud_name: "...",
|
24
25
|
api_key: "...",
|
25
26
|
api_secret: "...",
|
26
27
|
)
|
28
|
+
|
29
|
+
Shrine.storages = {
|
30
|
+
cache: Shrine::Storage::Cloudinary.new(prefix: "cache"), # for direct uploads
|
31
|
+
store: Shrine::Storage::Cloudinary.new(prefix: "store"),
|
32
|
+
}
|
27
33
|
```
|
28
34
|
|
29
|
-
|
35
|
+
### Direct uploads
|
30
36
|
|
31
|
-
|
32
|
-
|
37
|
+
Cloudinary supports uploading files directly to their service, freeing your
|
38
|
+
application from accepting file uploads. There are three ways in which you
|
39
|
+
can do direct uploads:
|
40
|
+
|
41
|
+
* [unsigned uploads using the widget](http://cloudinary.com/documentation/upload_widget)
|
42
|
+
* [unsigned uploads using jQuery](http://cloudinary.com/blog/direct_upload_made_easy_from_browser_or_mobile_app_to_the_cloud)
|
43
|
+
* [signed uploads via jQuery](http://cloudinary.com/documentation/jquery_image_upload)
|
44
|
+
|
45
|
+
The first one is the simplest, you can see the [demo] app with complete
|
46
|
+
implementation using shrine-cloudinary. Unsigned uploads don't require
|
47
|
+
communicating with the server, you just need to set up an "upload preset".
|
33
48
|
|
34
|
-
|
49
|
+
If you would prefer that the server controlls who is allowed to upload,
|
50
|
+
shrine-cloudinary also supports generating presigns, which works with the
|
51
|
+
direct_upload plugin in the same way that S3 does. When rendering on the server
|
52
|
+
side, you can generate a presign inline:
|
53
|
+
|
54
|
+
```erb
|
55
|
+
<input name="file" type="file"
|
56
|
+
class="cloudinary-fileupload" data-cloudinary-field="image_id"
|
57
|
+
data-form-data="<%= Shrine.storages[:cache].presign.fields.to_json %>" ></input>
|
35
58
|
```
|
36
59
|
|
37
|
-
|
60
|
+
Alternatively you can add an endpoint to your app which can generate presigns
|
61
|
+
on request, which is suitable for apps where templates are rendered on the
|
62
|
+
client-side (see [direct_upload] documentation):
|
38
63
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
64
|
+
```rb
|
65
|
+
Shrine.plugin :direct_upload, presign: true
|
66
|
+
```
|
67
|
+
```rb
|
68
|
+
Rails.application.routes.draw do
|
69
|
+
mount ImageUploader::UploadEndpoint => "/attachments/images"
|
70
|
+
end
|
71
|
+
```
|
43
72
|
|
44
73
|
### Copying
|
45
74
|
|
@@ -79,7 +108,7 @@ If you want some [Cloudinary options] to be applied to all uploads, you can
|
|
79
108
|
specify `:upload_options`:
|
80
109
|
|
81
110
|
```rb
|
82
|
-
Shrine::Storage::Cloudinary.new(upload_options: {
|
111
|
+
Shrine::Storage::Cloudinary.new(upload_options: {backup: true})
|
83
112
|
```
|
84
113
|
|
85
114
|
You can also apply upload options dynamically per upload using the
|
@@ -233,7 +262,7 @@ $ bundle exec rake test
|
|
233
262
|
|
234
263
|
## Inspiration
|
235
264
|
|
236
|
-
This gem has been inspired by
|
265
|
+
This gem has been inspired by Cloudinary's [CarrierWave integration].
|
237
266
|
|
238
267
|
## License
|
239
268
|
|
@@ -241,11 +270,11 @@ This gem has been inspired by [cloudinary]'s CarrierWave integration.
|
|
241
270
|
|
242
271
|
[Cloudinary]: http://cloudinary.com/
|
243
272
|
[Shrine]: https://github.com/janko-m/shrine
|
244
|
-
[
|
273
|
+
[CarrierWave integration]: https://github.com/cloudinary/cloudinary_gem
|
245
274
|
[Cloudinary options]: http://cloudinary.com/documentation/upload_images#remote_upload
|
246
275
|
[Rails image manipulation]: http://cloudinary.com/documentation/rails_image_manipulation
|
247
276
|
[responsive breakpoints]: http://cloudinary.com/blog/introducing_intelligent_responsive_image_breakpoints_solutions
|
248
277
|
[explicit API]: http://cloudinary.com/documentation/image_upload_api_reference#explicit
|
249
|
-
[direct unsigned uploads]: http://cloudinary.com/blog/direct_upload_made_easy_from_browser_or_mobile_app_to_the_cloud
|
250
278
|
[demo]: /demo
|
251
279
|
[control access]: http://cloudinary.com/documentation/upload_images#control_access_to_images
|
280
|
+
[direct_upload]: http://shrinerb.com/rdoc/classes/Shrine/Plugins/DirectUpload.html
|
@@ -69,7 +69,7 @@ class Shrine
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def url(id, **options)
|
72
|
-
::Cloudinary::Utils.cloudinary_url(path(id), default_options.merge(options))
|
72
|
+
::Cloudinary::Utils.cloudinary_url(path(id), default_options.merge(secure: true, **options))
|
73
73
|
end
|
74
74
|
|
75
75
|
def clear!(**options)
|
@@ -80,6 +80,20 @@ class Shrine
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
+
def presign(id = nil, **options)
|
84
|
+
upload_options.update(@upload_options)
|
85
|
+
upload_options.update(id ? {public_id: public_id(id)} : {folder: prefix})
|
86
|
+
|
87
|
+
fields = ::Cloudinary::Uploader.build_upload_params(upload_options.merge(options))
|
88
|
+
fields.reject! { |key, value| value.nil? || value == "" }
|
89
|
+
fields[:signature] = ::Cloudinary::Utils.api_sign_request(fields, ::Cloudinary.config.api_secret)
|
90
|
+
fields[:api_key] = ::Cloudinary.config.api_key
|
91
|
+
|
92
|
+
url = ::Cloudinary::Utils.cloudinary_api_url("upload", default_options)
|
93
|
+
|
94
|
+
Struct.new(:url, :fields).new(url, fields)
|
95
|
+
end
|
96
|
+
|
83
97
|
protected
|
84
98
|
|
85
99
|
def public_id(id)
|
data/shrine-cloudinary.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-cloudinary
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
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-06-
|
11
|
+
date: 2016-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shrine
|