uppy-s3_multipart 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +67 -36
- data/lib/shrine/plugins/uppy_s3_multipart.rb +4 -2
- data/uppy-s3_multipart.gemspec +2 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfe2ae799d5586b474000ff740cfc72d5e30ab0186098665ff50060693d3fc79
|
4
|
+
data.tar.gz: 4748896f3bcaae2f5de3b739e2cf1fe4d99754241165feff92cb4c6a2c92f486
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4fc57d8a84a1ce4b7444b20d99fc824ce7afe89dc4bb1da81765b24667ca5cacf53b289d8ee336c99530210f96d58ee839b10a425232505b19096007e385fd
|
7
|
+
data.tar.gz: 801e7e0f455a23d4db546898ed20b118a642279a7270988ace5cb39e5c15505a57eab6094c8eeb79f4b689ff88854cdfe5315655e105940cfb80ae3164487e6a
|
data/README.md
CHANGED
@@ -15,32 +15,38 @@ gem "uppy-s3_multipart"
|
|
15
15
|
|
16
16
|
## Setup
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
18
|
+
In order to allow direct multipart uploads to your S3 bucket, we need to update
|
19
|
+
the bucket's CORS configuration. In the AWS S3 Console go to your bucket, click
|
20
|
+
on "Permissions" tab and then on "CORS configuration". There paste in the
|
21
|
+
following:
|
22
|
+
|
23
|
+
```xml
|
24
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
25
|
+
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
|
26
|
+
<CORSRule>
|
27
|
+
<AllowedOrigin>https://my-app.com</AllowedOrigin>
|
28
|
+
<AllowedMethod>GET</AllowedMethod>
|
29
|
+
<AllowedMethod>POST</AllowedMethod>
|
30
|
+
<AllowedMethod>PUT</AllowedMethod>
|
31
|
+
<MaxAgeSeconds>3000</MaxAgeSeconds>
|
32
|
+
<AllowedHeader>Authorization</AllowedHeader>
|
33
|
+
<AllowedHeader>x-amz-date</AllowedHeader>
|
34
|
+
<AllowedHeader>x-amz-content-sha256</AllowedHeader>
|
35
|
+
<AllowedHeader>content-type</AllowedHeader>
|
36
|
+
<ExposeHeader>ETag</ExposeHeader>
|
37
|
+
</CORSRule>
|
38
|
+
<CORSRule>
|
39
|
+
<AllowedOrigin>*</AllowedOrigin>
|
40
|
+
<AllowedMethod>GET</AllowedMethod>
|
41
|
+
<MaxAgeSeconds>3000</MaxAgeSeconds>
|
42
|
+
</CORSRule>
|
43
|
+
</CORSConfiguration>
|
42
44
|
```
|
43
45
|
|
46
|
+
Replace `https://my-app.com` with the URL to your app (in development you can
|
47
|
+
set this to `*`). Once you've hit "Save", it may take some time for the new
|
48
|
+
CORS settings to be applied.
|
49
|
+
|
44
50
|
## Usage
|
45
51
|
|
46
52
|
This gem provides a Rack application that you can mount inside your main
|
@@ -91,15 +97,32 @@ POST /s3/multipart/:uploadId/complete
|
|
91
97
|
DELETE /s3/multipart/:uploadId
|
92
98
|
```
|
93
99
|
|
94
|
-
Finally, in your Uppy configuration
|
100
|
+
Finally, in your Uppy configuration point `serverUrl` to your app's URL:
|
95
101
|
|
96
102
|
```js
|
97
103
|
// ...
|
98
104
|
uppy.use(Uppy.AwsS3Multipart, {
|
99
|
-
serverUrl:
|
105
|
+
serverUrl: '/',
|
106
|
+
})
|
107
|
+
|
108
|
+
uppy.on('upload-success', function (file, data, uploadURL) {
|
109
|
+
var uploadedFileData = JSON.stringify({
|
110
|
+
id: uploadURL.match(/\/cache\/([^\?]+)/)[1], // extract key without prefix
|
111
|
+
storage: 'cache',
|
112
|
+
metadata: {
|
113
|
+
size: file.size,
|
114
|
+
filename: file.name,
|
115
|
+
mime_type: file.type,
|
116
|
+
}
|
117
|
+
})
|
118
|
+
// ...
|
100
119
|
})
|
101
120
|
```
|
102
121
|
|
122
|
+
**See [Adding Direct S3 Uploads] for an example of a complete Uppy setup with
|
123
|
+
Shrine. From there you can swap the `presign_endpoint` + `AwsS3` code with the
|
124
|
+
`uppy_s3_multipart` + `AwsS3Multipart` setup.**
|
125
|
+
|
103
126
|
Both the plugin and method accepts `:options` for specifying additional options
|
104
127
|
to the aws-sdk calls (read further for more details on these options):
|
105
128
|
|
@@ -115,9 +138,15 @@ Shrine.uppy_s3_multipart(:cache, options: {
|
|
115
138
|
})
|
116
139
|
```
|
117
140
|
|
141
|
+
Note that by default **Shrine won't extract metadata from directly upload
|
142
|
+
files**, instead it will just copy metadata that was extracted on the client
|
143
|
+
side. See [this section][metadata direct uploads] for the rationale and
|
144
|
+
instructions on how to opt in.
|
145
|
+
|
118
146
|
### Standalone
|
119
147
|
|
120
|
-
You can also
|
148
|
+
You can also use `uppy-s3_multipart` without Shrine. Start by initializing the
|
149
|
+
`Uppy::S3Multipart::App` directly:
|
121
150
|
|
122
151
|
```rb
|
123
152
|
require "uppy/s3_multipart"
|
@@ -147,12 +176,12 @@ map "/s3" do
|
|
147
176
|
end
|
148
177
|
```
|
149
178
|
|
150
|
-
In your Uppy configuration point
|
179
|
+
In your Uppy configuration point `serverUrl` to your app's URL:
|
151
180
|
|
152
181
|
```js
|
153
182
|
// ...
|
154
183
|
uppy.use(Uppy.AwsS3Multipart, {
|
155
|
-
serverUrl:
|
184
|
+
serverUrl: '/',
|
156
185
|
})
|
157
186
|
```
|
158
187
|
|
@@ -189,7 +218,7 @@ Initiates a new multipart upload.
|
|
189
218
|
|
190
219
|
```rb
|
191
220
|
client.create_multipart_upload(key: "foo", **options)
|
192
|
-
|
221
|
+
# => { upload_id: "MultipartUploadId", key: "foo" }
|
193
222
|
```
|
194
223
|
|
195
224
|
Accepts:
|
@@ -208,9 +237,9 @@ Retrieves currently uploaded parts of a multipart upload.
|
|
208
237
|
|
209
238
|
```rb
|
210
239
|
client.list_parts(upload_id: "MultipartUploadId", key: "foo", **options)
|
211
|
-
|
212
|
-
#
|
213
|
-
#
|
240
|
+
# => [ { part_number: 1, size: 5402383, etag: "etag1" },
|
241
|
+
# { part_number: 2, size: 5982742, etag: "etag2" },
|
242
|
+
# ... ]
|
214
243
|
```
|
215
244
|
|
216
245
|
Accepts:
|
@@ -233,7 +262,7 @@ Returns the endpoint that should be used for uploading a new multipart part.
|
|
233
262
|
|
234
263
|
```rb
|
235
264
|
client.prepare_upload_part(upload_id: "MultipartUploadId", key: "foo", part_number: 1, **options)
|
236
|
-
|
265
|
+
# => { url: "https://my-bucket.s3.amazonaws.com/foo?partNumber=1&uploadId=MultipartUploadId&..." }
|
237
266
|
```
|
238
267
|
|
239
268
|
Accepts:
|
@@ -253,7 +282,7 @@ Finalizes the multipart upload and returns URL to the object.
|
|
253
282
|
|
254
283
|
```rb
|
255
284
|
client.complete_multipart_upload(upload_id: upload_id, key: key, parts: [{ part_number: 1, etag: "etag1" }], **options)
|
256
|
-
|
285
|
+
# => { location: "https://my-bucket.s3.amazonaws.com/foo?..." }
|
257
286
|
```
|
258
287
|
|
259
288
|
Accepts:
|
@@ -273,7 +302,7 @@ Aborts the multipart upload, removing all parts uploaded so far.
|
|
273
302
|
|
274
303
|
```rb
|
275
304
|
client.abort_multipart_upload(upload_id: upload_id, key: key, **options)
|
276
|
-
|
305
|
+
# => {}
|
277
306
|
```
|
278
307
|
|
279
308
|
Accepts:
|
@@ -301,9 +330,11 @@ License](https://opensource.org/licenses/MIT).
|
|
301
330
|
|
302
331
|
[AwsS3Multipart]: https://uppy.io/docs/aws-s3-multipart/
|
303
332
|
[Shrine]: https://shrinerb.com
|
333
|
+
[Adding Direct S3 Uploads]: https://github.com/shrinerb/shrine/wiki/Adding-Direct-S3-Uploads
|
304
334
|
[`Aws::S3::Client#create_multipart_upload`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#create_multipart_upload-instance_method
|
305
335
|
[`Aws::S3::Client#list_parts`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#list_parts-instance_method
|
306
336
|
[`Aws::S3::Client#upload_part`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#upload_part-instance_method
|
307
337
|
[`Aws::S3::Presigner#presigned_url`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Presigner.html#presigned_url-instance_method
|
308
338
|
[`Aws::S3::Client#complete_multipart_upload`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#complete_multipart_upload-instance_method
|
309
339
|
[`Aws::S3::Client#abort_multipart_upload`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#abort_multipart_upload-instance_method
|
340
|
+
[metadata direct uploads]: https://github.com/shrinerb/shrine/blob/master/doc/metadata.md#direct-uploads
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require "uppy/s3_multipart"
|
2
2
|
|
3
|
-
require "securerandom"
|
4
|
-
|
5
3
|
class Shrine
|
6
4
|
module Plugins
|
7
5
|
module UppyS3Multipart
|
@@ -13,6 +11,10 @@ class Shrine
|
|
13
11
|
def uppy_s3_multipart(storage_key, **options)
|
14
12
|
s3 = find_storage(storage_key)
|
15
13
|
|
14
|
+
unless defined?(Shrine::Storage::S3) && s3.is_a?(Shrine::Storage::S3)
|
15
|
+
fail Error, "expected storage to be a Shrine::Storage::S3, but was #{s3.inspect}"
|
16
|
+
end
|
17
|
+
|
16
18
|
::Uppy::S3Multipart::App.new(
|
17
19
|
bucket: s3.bucket,
|
18
20
|
prefix: s3.prefix,
|
data/uppy-s3_multipart.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "uppy-s3_multipart"
|
3
|
-
gem.version = "0.1.
|
3
|
+
gem.version = "0.1.1"
|
4
4
|
|
5
5
|
gem.required_ruby_version = ">= 2.2"
|
6
6
|
|
@@ -20,5 +20,6 @@ Gem::Specification.new do |gem|
|
|
20
20
|
gem.add_development_dependency "minitest"
|
21
21
|
gem.add_development_dependency "rack-test_app"
|
22
22
|
gem.add_development_dependency "shrine", "~> 2.0"
|
23
|
+
gem.add_development_dependency "shrine-memory"
|
23
24
|
gem.add_development_dependency "aws-sdk-core", "~> 3.23"
|
24
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uppy-s3_multipart
|
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: 2018-
|
11
|
+
date: 2018-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: roda
|
@@ -100,6 +100,20 @@ dependencies:
|
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '2.0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: shrine-memory
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
103
117
|
- !ruby/object:Gem::Dependency
|
104
118
|
name: aws-sdk-core
|
105
119
|
requirement: !ruby/object:Gem::Requirement
|