diff --git a/README.md b/README.md index 11a6efb..49af03e 100644 --- a/README.md +++ b/README.md @@ -524,6 +524,14 @@ can change it to "attachment" if you want the browser to always force download: Tus::Server.opts[:disposition] = "attachment" ``` +## Extension + +If you need the extension in the file name, you can set `:file_extension` to true, default is false. + +```rb +Tus::Server.opts[:file_extension] = true +``` + ## Checksum The following checksum algorithms are supported for the `checksum` extension: diff --git a/lib/tus/server.rb b/lib/tus/server.rb index 43e8393..a204c35 100644 --- a/lib/tus/server.rb +++ b/lib/tus/server.rb @@ -81,7 +81,6 @@ class Server < Roda validate_upload_metadata! if request.headers["Upload-Metadata"] validate_upload_concat! if request.headers["Upload-Concat"] - uid = SecureRandom.hex info = Tus::Info.new( "Upload-Length" => request.headers["Upload-Length"], "Upload-Offset" => "0", @@ -91,6 +90,12 @@ class Server < Roda "Upload-Expires" => (Time.now + expiration_time).httpdate, ) + if opts[:file_extension] + uid = "#{SecureRandom.hex}#{File.extname(info.name)}" + else + uid = SecureRandom.hex + end + before_create(uid, info) if info.final?