server-proxied-file-upload
Accept file uploads through short-lived pre-signed object-storage URLs instead of API request bodies
Why
A route that receives file bytes puts every upload through the API process, its memory and timeouts, and the edge web application firewall. Firewalls inspect bodies as attack payloads, so ordinary documents can be blocked: Sarj Wiki Markdown imports were denied by Cloud Armor rule 932115 before reaching the backend. A pre-signed URL sends the bytes straight to private object storage, under a signature the server controls.
Fix
Add a route that returns a pre-signed upload URL (GCS V4 signed URL or S3 pre-signed PUT/POST) for a server-chosen private object key, with a short expiry (15 minutes or less), a fixed content type and a bounded size (x-goog-content-length-range or an S3 content-length-range policy). The client uploads to that URL and sends only the returned upload id. Before using the object, the server checks ownership, size, type and checksum.
Examples
from fastapi import APIRouter, UploadFile
router = APIRouter()
@router.post("/documents")async def upload(file: UploadFile) -> Document: ...from fastapi import APIRouter
router = APIRouter()
@router.post("/documents/uploads")def create_upload(user: CurrentUser) -> SignedUpload: return sign_document_upload(user.id)
@router.post("/documents")def create_document(request: DocumentFromUpload) -> Document: ...