Allow and recommend mounting on "/s3/multipart"

This allows defining other /s3/* routes without potential clashes when Uppy::S3Multipart::App isn't mounted last. One example of such route is "/s3/params", which is called by the AWS S3 Uppy plugin. We still keep backwards compatibility for users that currently have it mounted on "/s3".
parent 3c97c5e4
...@@ -78,11 +78,11 @@ inside your main application: ...@@ -78,11 +78,11 @@ inside your main application:
```rb ```rb
# Rails (config/routes.rb) # Rails (config/routes.rb)
Rails.application.routes.draw do Rails.application.routes.draw do
mount Shrine.uppy_s3_multipart(:cache) => "/s3" mount Shrine.uppy_s3_multipart(:cache) => "/s3/multipart"
end end
# Rack (config.ru) # Rack (config.ru)
map "/s3" do map "/s3/multipart" do
run Shrine.uppy_s3_multipart(:cache) run Shrine.uppy_s3_multipart(:cache)
end end
``` ```
...@@ -167,11 +167,11 @@ and mount it in your app in the same way: ...@@ -167,11 +167,11 @@ and mount it in your app in the same way:
```rb ```rb
# Rails (config/routes.rb) # Rails (config/routes.rb)
Rails.application.routes.draw do Rails.application.routes.draw do
mount UPPY_S3_MULTIPART_APP => "/s3" mount UPPY_S3_MULTIPART_APP => "/s3/multipart"
end end
# Rack (config.ru) # Rack (config.ru)
map "/s3" do map "/s3/multipart" do
run UPPY_S3_MULTIPART_APP run UPPY_S3_MULTIPART_APP
end end
``` ```
......
...@@ -24,10 +24,14 @@ module Uppy ...@@ -24,10 +24,14 @@ module Uppy
plugin :json plugin :json
plugin :json_parser plugin :json_parser
plugin :halt plugin :halt
plugin :path_rewriter
# allow mounting on "/s3" for backwards compatibility
rewrite_path "/multipart", ""
route do |r| route do |r|
# POST /multipart # POST /s3/multipart
r.post "multipart" do r.post true do
content_type = r.params["type"] content_type = r.params["type"]
filename = r.params["filename"] filename = r.params["filename"]
...@@ -43,8 +47,8 @@ module Uppy ...@@ -43,8 +47,8 @@ module Uppy
{ uploadId: result.fetch(:upload_id), key: result.fetch(:key) } { uploadId: result.fetch(:upload_id), key: result.fetch(:key) }
end end
# GET /multipart/:uploadId # GET /s3/multipart/:uploadId
r.get "multipart", String do |upload_id| r.get String do |upload_id|
key = param!("key") key = param!("key")
result = client_call(:list_parts, upload_id: upload_id, key: key) result = client_call(:list_parts, upload_id: upload_id, key: key)
...@@ -54,8 +58,8 @@ module Uppy ...@@ -54,8 +58,8 @@ module Uppy
end end
end end
# GET /multipart/:uploadId/:partNumber # GET /s3/multipart/:uploadId/:partNumber
r.get "multipart", String, String do |upload_id, part_number| r.get String, String do |upload_id, part_number|
key = param!("key") key = param!("key")
result = client_call(:prepare_upload_part, upload_id: upload_id, key: key, part_number: part_number) result = client_call(:prepare_upload_part, upload_id: upload_id, key: key, part_number: part_number)
...@@ -63,8 +67,8 @@ module Uppy ...@@ -63,8 +67,8 @@ module Uppy
{ url: result.fetch(:url) } { url: result.fetch(:url) }
end end
# POST /multipart/:uploadId/complete # POST /s3/multipart/:uploadId/complete
r.post "multipart", String, "complete" do |upload_id| r.post String, "complete" do |upload_id|
key = param!("key") key = param!("key")
parts = param!("parts") parts = param!("parts")
...@@ -81,8 +85,8 @@ module Uppy ...@@ -81,8 +85,8 @@ module Uppy
{ location: result.fetch(:location) } { location: result.fetch(:location) }
end end
# DELETE /multipart/:uploadId # DELETE /s3/multipart/:uploadId
r.delete "multipart", String do |upload_id| r.delete String do |upload_id|
key = param!("key") key = param!("key")
client_call(:abort_multipart_upload, upload_id: upload_id, key: key) client_call(:abort_multipart_upload, upload_id: upload_id, key: key)
......
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