Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uppy-s3_multipart
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
uppy-s3_multipart
Commits
618f6793
Unverified
Commit
618f6793
authored
Dec 08, 2018
by
Janko Marohnić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add #object_url for passing additional URL options
parent
8cfff0a9
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
3 deletions
+79
-3
README.md
README.md
+24
-0
app.rb
lib/uppy/s3_multipart/app.rb
+4
-2
client.rb
lib/uppy/s3_multipart/client.rb
+9
-1
app_test.rb
test/app_test.rb
+13
-0
client_test.rb
test/client_test.rb
+29
-0
No files found.
README.md
View file @
618f6793
...
...
@@ -307,6 +307,28 @@ Returns:
*
`: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`
Aborts the multipart upload, removing all parts uploaded so far.
...
...
@@ -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::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::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
[
metadata direct uploads
]:
https://github.com/shrinerb/shrine/blob/master/doc/metadata.md#direct-uploads
lib/uppy/s3_multipart/app.rb
View file @
618f6793
...
...
@@ -80,9 +80,11 @@ module Uppy
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
# DELETE /s3/multipart/:uploadId
...
...
lib/uppy/s3_multipart/client.rb
View file @
618f6793
...
...
@@ -43,7 +43,15 @@ module Uppy
**
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
def
abort_multipart_upload
(
upload_id
:,
key
:,
**
options
)
...
...
test/app_test.rb
View file @
618f6793
...
...
@@ -210,6 +210,19 @@ describe Uppy::S3Multipart::App do
assert_match
URI
.
regexp
,
response
.
body_json
[
"location"
]
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
response
=
app
.
post
"/s3/multipart/foo/complete"
,
json:
{
parts:
[]
}
...
...
test/client_test.rb
View file @
618f6793
...
...
@@ -118,6 +118,35 @@ describe Uppy::S3Multipart::Client do
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
it
"aborts the multipart upload"
do
@client
.
abort_multipart_upload
(
upload_id:
"bar"
,
key:
"foo"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment