shrine-transloadit 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -8
- data/lib/shrine/plugins/transloadit.rb +7 -0
- data/shrine-transloadit.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: 103994ecec1d21c32779635c5a44fa5e9c6bdf87
|
4
|
+
data.tar.gz: 2d8a3422d5fbc6905240915ddc75ff0bc7315d9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a85785e545c36594dedc6897e89615970f017eba1f2364cc9a9de62909e761c2bab4d752c8fbe9574766ed29f7f65886ce6d28d967c098a3059f95f74be05a0f
|
7
|
+
data.tar.gz: bb0dd002e5156cc62aec52df497655451d5cf3abba75f084a6701a4ac0dfa6f86bec971648c0d904fc481dc923f6cf3447807f68972b86caa03518746edb820f
|
data/README.md
CHANGED
@@ -21,28 +21,26 @@ gem "aws-sdk"
|
|
21
21
|
require "shrine"
|
22
22
|
require "shrine/storage/s3"
|
23
23
|
|
24
|
-
|
24
|
+
Shrine.storages[:store] = Shrine::Storage::S3.new(
|
25
25
|
access_key_id: "xyz",
|
26
26
|
secret_access_key: "abc",
|
27
27
|
region: "my-region",
|
28
28
|
bucket: "my-app",
|
29
|
-
|
30
|
-
|
31
|
-
Shrine.storages = {
|
32
|
-
cache: Shrine::Storage::S3.new(prefix: "cache", **s3_options),
|
33
|
-
store: Shrine::Storage::S3.new(prefix: "store", **s3_options),
|
34
|
-
}
|
29
|
+
)
|
35
30
|
|
36
31
|
Shrine.plugin :transloadit,
|
37
32
|
auth_key: "your transloadit key",
|
38
33
|
auth_secret: "your transloadit secret"
|
39
34
|
```
|
35
|
+
|
40
36
|
```rb
|
41
37
|
post "/webhooks/transloadit" do
|
42
38
|
Shrine::Attacher.transloadit_save(params)
|
43
39
|
end
|
44
40
|
```
|
45
41
|
|
42
|
+
With this setup you can do [direct uploads](#direct-uploads) to Transloadit.
|
43
|
+
|
46
44
|
## How it works
|
47
45
|
|
48
46
|
Transloadit works in a way that you create an "assembly", which contains all
|
@@ -56,6 +54,9 @@ a URL to the route in your app where you'd like Transloadit to POST the results
|
|
56
54
|
of processing. Then you can call the plugin again in the route to save the
|
57
55
|
results to your attachment column.
|
58
56
|
|
57
|
+
The **[demo app]** shows a complete implementation of this flow, and can serve
|
58
|
+
as a good baseline for your own implementation.
|
59
|
+
|
59
60
|
## Usage
|
60
61
|
|
61
62
|
Transloadit assemblies are built inside `#transloadit_process` method in your
|
@@ -209,6 +210,36 @@ response.reload!
|
|
209
210
|
response.finished? #=> true
|
210
211
|
```
|
211
212
|
|
213
|
+
### Direct uploads
|
214
|
+
|
215
|
+
Transloadit supports direct uploads, allowing you to do additional processing
|
216
|
+
on upload, along with a [jQuery plugin] for easy integration. Generally you
|
217
|
+
only want to do some light processing on direct uploads, and without any
|
218
|
+
exporting, so that you have better control over your Transloadit bandwidth.
|
219
|
+
|
220
|
+
When direct upload finishes, Transloadit returns information about the uploaded
|
221
|
+
files, including a temporary URL and useful metadata. You'll want to store both
|
222
|
+
to the database, URL you will need for additional processing after the record
|
223
|
+
is saved. This is the JavaScript needed to convert Transloadit's data hash into
|
224
|
+
Shrine's format:
|
225
|
+
|
226
|
+
```js
|
227
|
+
{
|
228
|
+
id: data['url'], // we save the URL
|
229
|
+
storage: 'cache',
|
230
|
+
metadata: {
|
231
|
+
size: data['size'],
|
232
|
+
filename: data['name'],
|
233
|
+
mime_type: data['mime'],
|
234
|
+
width: data['meta'] && data['meta']['width'],
|
235
|
+
height: data['meta'] && data['meta']['height'],
|
236
|
+
transloadit: data['meta'],
|
237
|
+
}
|
238
|
+
}
|
239
|
+
```
|
240
|
+
|
241
|
+
See the **[demo app]** for a complete implementation of direct uploads.
|
242
|
+
|
212
243
|
### Import & Export
|
213
244
|
|
214
245
|
Every `TransloaditFile` needs to have an import and an export step. This plugin
|
@@ -335,7 +366,7 @@ $ bundle exec rake test
|
|
335
366
|
|
336
367
|
## License
|
337
368
|
|
338
|
-
[MIT](LICENSE.txt)
|
369
|
+
[MIT](/LICENSE.txt)
|
339
370
|
|
340
371
|
[Shrine]: https://github.com/janko-m/shrine
|
341
372
|
[Transloadit]: https://transloadit.com/
|
@@ -343,3 +374,5 @@ $ bundle exec rake test
|
|
343
374
|
[transloadit gem]: https://github.com/transloadit/ruby-sdk
|
344
375
|
[robot and arguments]: https://transloadit.com/docs/conversion-robots/
|
345
376
|
[templates]: https://transloadit.com/docs/#templates
|
377
|
+
[jQuery plugin]: https://github.com/transloadit/jquery-sdk
|
378
|
+
[demo app]: /demo
|
@@ -13,6 +13,7 @@ class Shrine
|
|
13
13
|
raise Error, "The :auth_key is required for transloadit plugin" if uploader.opts[:transloadit_auth_key].nil?
|
14
14
|
raise Error, "The :auth_secret is required for transloadit plugin" if uploader.opts[:transloadit_auth_secret].nil?
|
15
15
|
|
16
|
+
uploader.storages[:cache] ||= UrlStorage.new
|
16
17
|
uploader.opts[:backgrounding_promote] ||= proc { transloadit_process }
|
17
18
|
end
|
18
19
|
|
@@ -260,6 +261,12 @@ class Shrine
|
|
260
261
|
@steps.any? && @steps.last.robot.end_with?("/store")
|
261
262
|
end
|
262
263
|
end
|
264
|
+
|
265
|
+
class UrlStorage
|
266
|
+
def url(id, **options)
|
267
|
+
id
|
268
|
+
end
|
269
|
+
end
|
263
270
|
end
|
264
271
|
|
265
272
|
register_plugin(:transloadit, Transloadit)
|
data/shrine-transloadit.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shrine-transloadit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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-07-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shrine
|