Video in progress
A user uploads a large file (video, image). How do you accept it without passing the file through the backend?
The backend creates a short-lived presigned URL for object storage (S3 or MinIO), the client uploads the file straight to the storage, and then tells the backend "uploaded". The backend's threads and network don't carry the file.
📖 Answer
When a file passes through the backend, a 2 GB video holds a thread, memory or disk for several minutes, runs into balancer timeouts, and 10 parallel uploads slow the service down.
The presigned URL flow:
- Client:
POST /uploads {fileName, size, contentType}. - The backend checks permissions, size and type, creates a
PENDINGrecord in the DB and returns a 15-minute URL. - The client uploads the file straight to the storage with
PUT. - The client sends
POST /uploads/{id}/complete(or the storage notifies via an event), and the backend checks that the object exists and its size, then marks itREADY.
// AWS SDK v2
PutObjectRequest put = PutObjectRequest.builder()
.bucket("media").key("raw/" + uploadId)
.contentType("video/mp4").build();
PresignedPutObjectRequest req = presigner.presignPutObject(b -> b
.signatureDuration(Duration.ofMinutes(15))
.putObjectRequest(put));
return req.url().toString();
For large files, use multipart upload: the file is split into parts, and if the connection drops, only one part has to be re-uploaded.
Note: don't trust the contentType the client declares — check the file type yourself after the upload, and if it's a video, queue the processing (transcoding). You also need a job that cleans up records stuck in PENDING and half-uploaded parts.
Sign up to mark studied questions and save your progress.