Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion lib/tus/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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?
Expand Down