Minor documentation improvements

parent f9165a37
...@@ -56,14 +56,14 @@ directly. ...@@ -56,14 +56,14 @@ directly.
### Shrine ### Shrine
In the initializer load the `uppy_s3_multipart` plugin: In your Shrine initializer load the `uppy_s3_multipart` plugin:
```rb ```rb
require "shrine" require "shrine"
require "shrine/storage/s3" require "shrine/storage/s3"
Shrine.storages = { Shrine.storages = {
cache: Shrine::Storage::S3.new(...), cache: Shrine::Storage::S3.new(prefix: "cache", ...),
store: Shrine::Storage::S3.new(...), store: Shrine::Storage::S3.new(...),
} }
...@@ -97,14 +97,20 @@ POST /s3/multipart/:uploadId/complete ...@@ -97,14 +97,20 @@ POST /s3/multipart/:uploadId/complete
DELETE /s3/multipart/:uploadId DELETE /s3/multipart/:uploadId
``` ```
Finally, in your Uppy configuration point `serverUrl` to your app's URL: Now in your Uppy configuration point `serverUrl` to your app's URL:
```js ```js
// ... // ...
uppy.use(Uppy.AwsS3Multipart, { uppy.use(Uppy.AwsS3Multipart, {
serverUrl: '/', serverUrl: '/',
}) })
```
In the `upload-success` Uppy callback you can then construct the Shrine
uploaded file data (this example assumes your temporary Shrine S3 storage has
`prefix: "cache"` set):
```js
uppy.on('upload-success', function (file, data, uploadURL) { uppy.on('upload-success', function (file, data, uploadURL) {
var uploadedFileData = JSON.stringify({ var uploadedFileData = JSON.stringify({
id: uploadURL.match(/\/cache\/([^\?]+)/)[1], // extract key without prefix id: uploadURL.match(/\/cache\/([^\?]+)/)[1], // extract key without prefix
...@@ -123,8 +129,14 @@ uppy.on('upload-success', function (file, data, uploadURL) { ...@@ -123,8 +129,14 @@ uppy.on('upload-success', function (file, data, uploadURL) {
Shrine. From there you can swap the `presign_endpoint` + `AwsS3` code with the Shrine. From there you can swap the `presign_endpoint` + `AwsS3` code with the
`uppy_s3_multipart` + `AwsS3Multipart` setup.** `uppy_s3_multipart` + `AwsS3Multipart` setup.**
Both the plugin and method accepts `:options` for specifying additional options Note that by default **Shrine won't extract metadata from directly upload
to the aws-sdk calls (read further for more details on these options): files**, instead it will just copy metadata that was extracted on the client
side. See [this section][metadata direct uploads] for the rationale and
instructions on how to opt in.
Both the plugin and method accept `:options` for specifying additional options
to the S3 client operations (see the [Client](#client) section for list of
operations and options they accept):
```rb ```rb
Shrine.plugin :uppy_s3_multipart, options: { Shrine.plugin :uppy_s3_multipart, options: {
...@@ -138,14 +150,11 @@ Shrine.uppy_s3_multipart(:cache, options: { ...@@ -138,14 +150,11 @@ Shrine.uppy_s3_multipart(:cache, options: {
}) })
``` ```
Note that by default **Shrine won't extract metadata from directly upload In the dynamic version the yielded object is an instance of [`Rack::Request`].
files**, instead it will just copy metadata that was extracted on the client
side. See [this section][metadata direct uploads] for the rationale and
instructions on how to opt in.
### Standalone ### App
You can also use `uppy-s3_multipart` without Shrine. Start by initializing the You can also use `uppy-s3_multipart` without Shrine, by initializing the
`Uppy::S3Multipart::App` directly: `Uppy::S3Multipart::App` directly:
```rb ```rb
...@@ -162,7 +171,7 @@ bucket = resource.bucket("my-bucket") ...@@ -162,7 +171,7 @@ bucket = resource.bucket("my-bucket")
UPPY_S3_MULTIPART_APP = Uppy::S3Multipart::App.new(bucket: bucket) UPPY_S3_MULTIPART_APP = Uppy::S3Multipart::App.new(bucket: bucket)
``` ```
and mount it in your app in the same way: You can mount it inside your main app in the same way:
```rb ```rb
# Rails (config/routes.rb) # Rails (config/routes.rb)
...@@ -186,24 +195,26 @@ uppy.use(Uppy.AwsS3Multipart, { ...@@ -186,24 +195,26 @@ uppy.use(Uppy.AwsS3Multipart, {
``` ```
The `Uppy::S3Mutipart::App` initializer accepts `:options` for specifying The `Uppy::S3Mutipart::App` initializer accepts `:options` for specifying
additional options to the aws-sdk calls (read further for more details on these additional options to the S3 client operations (see the [Client](#client)
options): section for list of operations and options they accept):
```rb ```rb
Uppy::S3Multipart::App.new(bucket: bucket, options: { Uppy::S3Multipart::App.new(bucket: bucket, options: {
create_multipart_upload: { acl: "public-read" } create_multipart_upload: { acl: "public-read" } # static
}) })
# OR # OR
Uppy::S3Multipart::App.new(bucket: bucket, options: { Uppy::S3Multipart::App.new(bucket: bucket, options: {
create_multipart_upload: -> (request) { { acl: "public-read" } } create_multipart_upload: -> (request) { { acl: "public-read" } } # dynamic
}) })
``` ```
### Custom implementation In the dynamic version the yielded object is an instance of [`Rack::Request`].
### Client
If you would rather implement the endpoints yourself, you can utilize If you would rather implement the endpoints yourself, you can utilize the
`Uppy::S3Multipart::Client` to make S3 requests. `Uppy::S3Multipart::Client` to make S3 requests.
```rb ```rb
...@@ -223,13 +234,13 @@ client.create_multipart_upload(key: "foo", **options) ...@@ -223,13 +234,13 @@ client.create_multipart_upload(key: "foo", **options)
Accepts: Accepts:
* `:key` -- object key * `:key` object key
* additional options for [`Aws::S3::Client#create_multipart_upload`] * additional options for [`Aws::S3::Client#create_multipart_upload`]
Returns: Returns:
* `:upload_id` -- id of the created multipart upload * `:upload_id` id of the created multipart upload
* `:key` -- object key * `:key` object key
#### `#list_parts` #### `#list_parts`
...@@ -244,17 +255,17 @@ client.list_parts(upload_id: "MultipartUploadId", key: "foo", **options) ...@@ -244,17 +255,17 @@ client.list_parts(upload_id: "MultipartUploadId", key: "foo", **options)
Accepts: Accepts:
* `:upload_id` -- multipart upload id * `:upload_id` multipart upload id
* `:key` -- object key * `:key` object key
* additional options for [`Aws::S3::Client#list_parts`] * additional options for [`Aws::S3::Client#list_parts`]
Returns: Returns:
* array of parts * array of parts
- `:part_number` -- position of the part - `:part_number` position of the part
- `:size` -- filesize of the part - `:size` filesize of the part
- `:etag` -- etag of the part - `:etag` etag of the part
#### `#prepare_upload_part` #### `#prepare_upload_part`
...@@ -267,14 +278,14 @@ client.prepare_upload_part(upload_id: "MultipartUploadId", key: "foo", part_numb ...@@ -267,14 +278,14 @@ client.prepare_upload_part(upload_id: "MultipartUploadId", key: "foo", part_numb
Accepts: Accepts:
* `:upload_id` -- multipart upload id * `:upload_id` multipart upload id
* `:key` -- object key * `:key` object key
* `:part_number` -- number of the next part * `:part_number` number of the next part
* additional options for [`Aws::S3::Client#upload_part`] and [`Aws::S3::Presigner#presigned_url`] * additional options for [`Aws::S3::Client#upload_part`] and [`Aws::S3::Presigner#presigned_url`]
Returns: Returns:
* `:url` -- endpoint that should be used for uploading a new multipart part via a `PUT` request * `:url` endpoint that should be used for uploading a new multipart part via a `PUT` request
#### `#complete_multipart_upload` #### `#complete_multipart_upload`
...@@ -287,14 +298,14 @@ client.complete_multipart_upload(upload_id: upload_id, key: key, parts: [{ part_ ...@@ -287,14 +298,14 @@ client.complete_multipart_upload(upload_id: upload_id, key: key, parts: [{ part_
Accepts: Accepts:
* `:upload_id` -- multipart upload id * `:upload_id` multipart upload id
* `:key` -- object key * `:key` object key
* `:parts` -- list of all uploaded parts, consisting of `:part_number` and `:etag` * `:parts` list of all uploaded parts, consisting of `:part_number` and `:etag`
* additional options for [`Aws::S3::Client#complete_multipart_upload`] * additional options for [`Aws::S3::Client#complete_multipart_upload`]
Returns: Returns:
* `:location` -- URL to the uploaded object * `:location` URL to the uploaded object
#### `#abort_multipart_upload` #### `#abort_multipart_upload`
...@@ -307,8 +318,8 @@ client.abort_multipart_upload(upload_id: upload_id, key: key, **options) ...@@ -307,8 +318,8 @@ client.abort_multipart_upload(upload_id: upload_id, key: key, **options)
Accepts: Accepts:
* `:upload_id` -- multipart upload id * `:upload_id` multipart upload id
* `:key` -- object key * `:key` object key
* additional options for [`Aws::S3::Client#abort_multipart_upload`] * additional options for [`Aws::S3::Client#abort_multipart_upload`]
## Contributing ## Contributing
...@@ -331,6 +342,7 @@ License](https://opensource.org/licenses/MIT). ...@@ -331,6 +342,7 @@ License](https://opensource.org/licenses/MIT).
[AwsS3Multipart]: https://uppy.io/docs/aws-s3-multipart/ [AwsS3Multipart]: https://uppy.io/docs/aws-s3-multipart/
[Shrine]: https://shrinerb.com [Shrine]: https://shrinerb.com
[Adding Direct S3 Uploads]: https://github.com/shrinerb/shrine/wiki/Adding-Direct-S3-Uploads [Adding Direct S3 Uploads]: https://github.com/shrinerb/shrine/wiki/Adding-Direct-S3-Uploads
[`Rack::Request`]: https://www.rubydoc.info/github/rack/rack/master/Rack/Request
[`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 [`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
[`Aws::S3::Client#list_parts`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#list_parts-instance_method [`Aws::S3::Client#list_parts`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#list_parts-instance_method
[`Aws::S3::Client#upload_part`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#upload_part-instance_method [`Aws::S3::Client#upload_part`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#upload_part-instance_method
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment