Add curl-friendly file upload via PUT #66

Merged
heiko merged 4 commits from feat/43-curl-upload into master 2026-06-16 22:34:23 +02:00
Owner

Support uploading files with curl without needing multipart forms:

# Simple upload (filename from local file)
curl -u user:pass -T myfile.pdf https://once.example.com/

# With explicit filename
curl -u user:pass -X PUT --data-binary @myfile.pdf \
     "https://once.example.com/?name=myfile.pdf"

# Multipart (like the HTML form, but plain-text response)
curl -u user:pass -F file=@doc.txt https://once.example.com/

Returns 201 Created with the download URL as plain text.

Changes

  • Accept PUT with raw body; filename resolved from ?name= query param, Content-Disposition header, or URL path (curl -T appends the filename)
  • For POST multipart: detect non-browser clients (Accept: */* without text/html) and return plain-text URLs instead of HTML
  • Accept file as alternate multipart field name (besides legacy .file) for curl -F compatibility
  • Tests for wantsPlainText() and handlePutUpload()

Fixes #43

Support uploading files with curl without needing multipart forms: ```bash # Simple upload (filename from local file) curl -u user:pass -T myfile.pdf https://once.example.com/ # With explicit filename curl -u user:pass -X PUT --data-binary @myfile.pdf \ "https://once.example.com/?name=myfile.pdf" # Multipart (like the HTML form, but plain-text response) curl -u user:pass -F file=@doc.txt https://once.example.com/ ``` Returns `201 Created` with the download URL as plain text. ## Changes - Accept `PUT` with raw body; filename resolved from `?name=` query param, `Content-Disposition` header, or URL path (curl -T appends the filename) - For `POST` multipart: detect non-browser clients (`Accept: */*` without `text/html`) and return plain-text URLs instead of HTML - Accept `file` as alternate multipart field name (besides legacy `.file`) for `curl -F` compatibility - Tests for `wantsPlainText()` and `handlePutUpload()` Fixes #43
Support uploading files with curl without needing multipart forms:

  curl -u user:pass -T myfile.pdf https://once.example.com/
  curl -u user:pass -F file=@doc.txt https://once.example.com/

Changes:
- Accept PUT with raw body; filename from ?name= param,
  Content-Disposition header, or URL path (curl -T appends filename)
- Return 201 Created with plain-text download URL for PUT requests
- For POST multipart: detect non-browser clients (Accept: */* without
  text/html) and return plain-text URLs instead of HTML
- Accept 'file' as alternate multipart field name (in addition to
  legacy '.file') for curl -F compatibility
- Add tests for wantsPlainText() and handlePutUpload()

Fixes #43
heiko requested review from mf 2026-05-27 17:58:57 +02:00
- Return 400 Bad Request for PUT with empty body
- Add TestPutUploadSizeLimit: verifies oversized PUT is rejected
- Add TestPutUploadEmptyBody: verifies empty PUT is rejected
heiko merged commit dd73e99d11 into master 2026-06-16 22:34:23 +02:00
heiko deleted branch feat/43-curl-upload 2026-06-16 22:34:24 +02:00
Sign in to join this conversation.
No description provided.