Add #object_url for passing additional URL options

parent 8cfff0a9
...@@ -307,6 +307,28 @@ Returns: ...@@ -307,6 +307,28 @@ Returns:
* `:location` – URL to the uploaded object * `:location` – URL to the uploaded object
#### `#object_url`
Generates URL to the object.
```rb
client.object_url(key: key, **options)
# => "https://my-bucket.s3.amazonaws.com/foo?..."
```
This is called after `#complete_multipart_upload` in the app and returned in
the response.
Accepts:
* `:key` – object key
* `:public` – for generating a public URL (default is presigned expiring URL)
* additional options for [`Aws::S3::Object#presigned_url`] and [`Aws::S3::Client#get_object`]
Returns:
* URL to the object
#### `#abort_multipart_upload` #### `#abort_multipart_upload`
Aborts the multipart upload, removing all parts uploaded so far. Aborts the multipart upload, removing all parts uploaded so far.
...@@ -348,5 +370,7 @@ License](https://opensource.org/licenses/MIT). ...@@ -348,5 +370,7 @@ License](https://opensource.org/licenses/MIT).
[`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
[`Aws::S3::Presigner#presigned_url`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Presigner.html#presigned_url-instance_method [`Aws::S3::Presigner#presigned_url`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Presigner.html#presigned_url-instance_method
[`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 [`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
[`Aws::S3::Object#presigned_url`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Object.html#presigned_url-instance_method
[`Aws::S3::Client#get_object`]: https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/S3/Client.html#get_object-instance_method
[`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 [`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
[metadata direct uploads]: https://github.com/shrinerb/shrine/blob/master/doc/metadata.md#direct-uploads [metadata direct uploads]: https://github.com/shrinerb/shrine/blob/master/doc/metadata.md#direct-uploads
...@@ -80,9 +80,11 @@ module Uppy ...@@ -80,9 +80,11 @@ module Uppy
end end
end end
result = client_call(:complete_multipart_upload, upload_id: upload_id, key: key, parts: parts) client_call(:complete_multipart_upload, upload_id: upload_id, key: key, parts: parts)
{ location: result.fetch(:location) } object_url = client_call(:object_url, key: key)
{ location: object_url }
end end
# DELETE /s3/multipart/:uploadId # DELETE /s3/multipart/:uploadId
......
...@@ -43,7 +43,15 @@ module Uppy ...@@ -43,7 +43,15 @@ module Uppy
**options **options
) )
{ location: object(key).presigned_url(:get) } { location: object_url(key: key) }
end
def object_url(key:, public: nil, **options)
if public
object(key).public_url(**options)
else
object(key).presigned_url(:get, **options)
end
end end
def abort_multipart_upload(upload_id:, key:, **options) def abort_multipart_upload(upload_id:, key:, **options)
......
...@@ -210,6 +210,19 @@ describe Uppy::S3Multipart::App do ...@@ -210,6 +210,19 @@ describe Uppy::S3Multipart::App do
assert_match URI.regexp, response.body_json["location"] assert_match URI.regexp, response.body_json["location"]
end end
it "applies options for object URL" do
@endpoint = Uppy::S3Multipart::App.new(bucket: @bucket, options: {
object_url: { response_content_disposition: "attachment" }
})
response = app.post "/s3/multipart/foo/complete", query: { key: "bar" }, json: { parts: [] }
assert_equal 200, response.status
assert_equal "application/json", response.headers["Content-Type"]
assert_includes response.body_json["location"], "response-content-disposition"
end
it "returns error response when 'key' parameter is missing" do it "returns error response when 'key' parameter is missing" do
response = app.post "/s3/multipart/foo/complete", json: { parts: [] } response = app.post "/s3/multipart/foo/complete", json: { parts: [] }
......
...@@ -118,6 +118,35 @@ describe Uppy::S3Multipart::Client do ...@@ -118,6 +118,35 @@ describe Uppy::S3Multipart::Client do
end end
end end
describe "#object_url" do
it "returns presigned object URL" do
url = @client.object_url(key: "foo")
uri = URI.parse(url)
assert_includes uri.host, "my-bucket"
assert_equal "/foo", uri.path
refute_nil uri.query
end
it "accepts :public option for public URLs" do
url = @client.object_url(key: "foo", public: true)
uri = URI.parse(url)
assert_includes uri.host, "my-bucket"
assert_equal "/foo", uri.path
assert_nil uri.query
end
it "forwards additional options to the aws-sdk call" do
url = @client.object_url(key: "foo", response_content_disposition: "attachment")
uri = URI.parse(url)
assert_includes uri.host, "my-bucket"
assert_equal "/foo", uri.path
assert_includes uri.query, "response-content-disposition"
end
end
describe "#abort_multipart_upload" do describe "#abort_multipart_upload" do
it "aborts the multipart upload" do it "aborts the multipart upload" do
@client.abort_multipart_upload(upload_id: "bar", key: "foo") @client.abort_multipart_upload(upload_id: "bar", key: "foo")
......
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