Routing client file uploads directly from web browsers to an object storage bucket eliminates web application server bottlenecks. Instead of proxying multi-gigabyte video files or disk archives through an application process—consuming application memory, CPU cycles, and network bandwidth—the client transmits bytes directly to the object store endpoint over HTTPS.
Historically, Amazon S3 provided two mechanisms for direct uploads: <b>Presigned POST policies</b> (designed for legacy <code><form method="POST" enctype="multipart/form-data"></code> submissions) and <b>Presigned PUT URLs</b> (designed for REST clients and modern Fetch/XHR requests). While presigned POST policy documents offer declarative constraints such as <code>content-length-range</code> and <code>starts-with</code>, modern edge storage gateways frequently restrict or reject raw HTML form POST operations. Understanding these architectural differences ensures robust direct-to-bucket client integrations.
HTML Form POST policies vs Presigned PUT URLs
An S3 Presigned POST operation requires generating a base64-encoded JSON policy document containing an expiration timestamp and condition assertions. The form fields and policy are signed with AWS Signature Version 4. A standard policy specifies exact equality conditions or prefix boundaries:
In theory, this allows a raw HTML form in a browser to submit a multipart body directly to <code>https://<bucket>.s3.amazonaws.com/</code> without JavaScript. However, in modern cloud architectures and edge object stores, <code>PostObject</code> is widely treated as legacy or explicitly unsupported. Testing direct browser multipart POST against modern S3-compatible gateways (including edge gateways like tport.space) yields <code>HTTP 403 AccessDenied</code> or <code>HTTP 501 NotImplemented</code> because the storage gateway routes only standard REST primitives (<code>PUT</code>, <code>GET</code>, <code>DELETE</code>, <code>HEAD</code>).
Consequently, production systems standardise on <b>Presigned PUT URLs</b> paired with the browser <code>fetch()</code> API. Rather than relying on a complex multipart form parser inside the storage gateway, presigned PUT signs the exact HTTP method, path, and request headers cryptographically.
MIME type enforcement: Cryptographic SigV4 header signing
A common security requirement is preventing users from uploading arbitrary or malicious file types (e.g., executing HTML/JavaScript in an SVG, or uploading binaries disguised as images). With Presigned PUT URLs, MIME type enforcement is achieved at the storage tier by including the <code>Content-Type</code> header inside the SigV4 <code>SignedHeaders</code> list during URL generation.
When the backend signs the URL with <code>ContentType='image/png'</code>, the storage engine calculates the canonical request hash incorporating that exact header. We tested three distinct client scenarios against live storage endpoints:
| Test scenario | Signed Content-Type | Client sent Content-Type | HTTP status | Gateway response |
|---|---|---|---|---|
| Matching MIME | image/png | image/png | 200 OK | Signature verified; object committed to storage |
| Mismatched MIME | image/png | text/html | 403 Forbidden | SignatureDoesNotMatch; canonical hash mismatch |
| Omitted header | image/png | (None) | 403 Forbidden | SignatureDoesNotMatch; signed header absent from request |
| Path tampering | image/png | image/png (altered key) | 403 Forbidden | SignatureDoesNotMatch; canonical URI mismatch |
Because SigV4 validates the entire canonical request before accepting object bytes, any modification by a malicious client—whether altering the MIME type to bypass validation, stripping headers, or rewriting the target storage key path—is rejected immediately at the edge. The upload never touches the bucket.
Size constraints: Content-length-range vs signed exact length
The primary functional difference between POST policies and presigned PUT URLs lies in size enforcement. Presigned POST policy documents support <code>content-length-range</code> (e.g., between 1 KiB and 10 MiB), enabling flexible file uploads where the exact size is unknown until the user selects the file in their browser.
Standard SigV4 presigned PUT URLs, by contrast, sign HTTP headers as exact key-value pairs. There is no concept of a mathematical range in HTTP request headers. As our live test confirmed, when a presigned PUT URL is generated without binding <code>Content-Length</code> in <code>SignedHeaders</code>, the gateway accepts any valid upload payload (tested at 1 KiB and 2 KiB) up to the storage system's maximum allowed single-part payload limit.
To strictly enforce file size limits when using presigned PUT URLs, architectures employ a two-layer control:
- Pre-signing handshake: The browser selects the file, checks
file.size, and requests a presigned URL from the application backend passing the exact byte count. The backend validates thatfile.size <= MAX_BYTESand signsContent-Lengthinto the PUT URL headers. If the client subsequently attempts to send more or fewer bytes than stated, the upload fails withHTTP 403 SignatureDoesNotMatchor connection termination. - Client-side pre-flight guard: Modern JavaScript validates file extension, MIME type, and size before initiating the HTTP handshake, preventing wasted upload bandwidth.
Production implementation: Backend signing and browser client
Below is a complete, production-ready implementation using Python (Boto3) on the backend and native JavaScript Fetch on the client.
<b>Backend (Python FastAPI / Boto3):</b>
<b>Frontend (Modern Browser JavaScript):</b>
CORS requirements for direct browser uploads
Because the browser initiates a cross-origin HTTP <code>PUT</code> from the web application domain (e.g., <code>https://app.example.com</code>) to the storage endpoint (e.g., <code>https://s3.tport.space</code>), the target bucket must have an active CORS configuration. The CORS policy must allow the <code>PUT</code> verb and explicitly expose headers:
Architectural guidelines
- Avoid POST policies on S3-compatible backends: PostObject is unsupported across numerous edge storage gateways. Standardising on Presigned PUT provides compatibility across AWS S3, Cloudflare R2, MinIO, and tport.space.
- Always sign Content-Type: Omission allows clients to upload malicious executables or scripts under arbitrary MIME classifications. Signing
ContentTypeguarantees that the uploaded byte stream matches the declared format. - Set tight URL expiration windows: Configure presigned upload URLs with short TTLs (typically 5 to 15 minutes). Once an upload completes, the URL should lapse to prevent reuse.
- Validate magic bytes post-upload: If user-uploaded images or documents are subsequently served publicly, trigger an asynchronous background worker to verify magic bytes before publishing.