Short answer: use a small application control plane to authorize a private upload, create a multipart session, and issue short-lived presigned URLs for each part. Let the browser send bytes directly to object storage, then let the control plane complete or abort the session. This keeps access control in the application without making the application server carry the file.
That is the least complex design that still gives an edtech product a useful recovery story for a large lecture recording, assignment archive, or dataset. It also makes the important failure visible: an upload is a state machine, not a single request.
Check the owner first.
The decision is a boundary, not a vendor choice
Before choosing an SDK or storage service, decide which side of the boundary owns each fact. The application owns identity, policy, and the upload record. Storage owns part transfer and assembly. This decision survives a provider change; a provider-specific URL format does not.
No magic.
The incident lesson: a completed upload is not a delivered file
The production scenario is bounded and familiar: a student selects a private lecture recording, the browser uploads every part, and the UI shows success. A later download request still needs a fresh authorization decision. If the application treats the upload URL as proof of read access, or if it marks the row complete before storage confirms completion, the system has confused delivery with authorization. I've seen enough missed jobs and duplicate deliveries to distrust a green progress bar on its own.
The invariant is simple: the application owns identity and state; object storage owns byte transfer. Keep those responsibilities separate and a retry remains a retry instead of a second delivery. It sounds obvious. Production has a way of making obvious rules expensive.
How should a browser upload large files with presigned multipart parts?
The browser should never decide who may read or write an object. It asks the application for an upload session. The application authenticates the user, validates the declared size and content type, chooses an object key, and records the owner, expiry, expected part count, and status before returning URLs.
The browser uploads each numbered part directly to storage. It sends the resulting part identifier back to the application. The application verifies that the part belongs to the session and, only after all expected parts are accounted for, completes the upload. Download access is a separate decision: issue a short-lived presigned GET only after the user is allowed to see that object.
That session row should contain more than an object key. Persist the authenticated owner, expected byte size, part size, expected part count, storage upload ID, application deadline, and terminal status. Those fields let a reconciler distinguish a slow transfer from a client that vanished. They also let support answer the only question that matters during an incident: who was allowed to finish this upload, and what did the system believe had happened?
Here is the control-plane shape in Go. The storage client is intentionally behind the workflow; the HTTP handlers around it should enforce authentication, authorization, size limits, and origin policy.
package upload
import (
"context"
"fmt"
"sort"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
const partSize int64 = 16 * 1024 * 1024
type Part struct {
Number int32
ETag string
}
type Session struct {
Bucket string
Key string
UploadID string
PartCount int32
ExpiresAt time.Time
}
func Start(ctx context.Context, client *s3.Client, bucket, key string, size int64) (Session, error) {
if size <= 0 {
return Session{}, fmt.Errorf("size must be positive")
}
created, err := client.CreateMultipartUpload(ctx, &s3.CreateMultipartUploadInput{
Bucket: aws.String(bucket),
Key: aws.String(key),
})
if err != nil {
return Session{}, err
}
count := int32((size + partSize - 1) / partSize)
return Session{
Bucket: bucket, Key: key, UploadID: aws.ToString(created.UploadId),
PartCount: count, ExpiresAt: time.Now().Add(15 * time.Minute),
}, nil
}
func Complete(ctx context.Context, client *s3.Client, session Session, parts []Part) error {
if len(parts) != int(session.PartCount) {
return fmt.Errorf("expected %d parts, got %d", session.PartCount, len(parts))
}
sort.Slice(parts, func(i, j int) bool { return parts[i].Number < parts[j].Number })
completed := make([]types.CompletedPart, len(parts))
for i, part := range parts {
if part.Number != int32(i+1) || part.ETag == "" {
return fmt.Errorf("invalid part %d", part.Number)
}
completed[i] = types.CompletedPart{ETag: aws.String(part.ETag), PartNumber: aws.Int32(part.Number)}
}
_, err := client.CompleteMultipartUpload(ctx, &s3.CompleteMultipartUploadInput{
Bucket: aws.String(session.Bucket), Key: aws.String(session.Key), UploadId: aws.String(session.UploadID),
MultipartUpload: &types.CompletedMultipartUpload{Parts: completed},
})
return err
}
func Abort(ctx context.Context, client *s3.Client, session Session) error {
_, err := client.AbortMultipartUpload(ctx, &s3.AbortMultipartUploadInput{
Bucket: aws.String(session.Bucket), Key: aws.String(session.Key), UploadId: aws.String(session.UploadID),
})
return err
}
The example omits one import for readability of the workflow: types is github.com/aws/aws-sdk-go-v2/service/s3/types. In a real service, persist the session before returning any presigned URL, and generate those URLs from the same bucket, key, upload ID, and part numbers. The browser may retry one part, but a retry should replace that part's recorded ETag. It should not create a second logical part.
One more rule matters. Completion must be idempotent. Store the terminal object metadata and return it when the same client request is repeated. A timeout after storage completes is normal network ambiguity; treating the retry as a new upload creates the duplicate-delivery incident the design was meant to avoid.
What should happen when completion, cancellation, and expiry race?
Three requests commonly arrive in an inconvenient order: a part retry, a user cancellation, and completion. Define the allowed transitions in the database: pending -> uploading -> complete, or pending/uploading -> aborted. A terminal row stays terminal. Completion checks ownership, session expiry, the exact part set, and the current status in one transaction before calling storage.
That last detail deserves emphasis. A transaction cannot roll back a storage completion. Use a small reconciliation job for the uncertain window: if storage reports completion but the application timed out before recording it, inspect the session and repair the row. If cancellation wins, call abort and mark the row aborted. The background job should retry an abort and report the attempt; it should not silently delete application evidence.
The hard case is a timeout after the storage service has accepted the final request. The browser sees no response, retries, and may race a support-triggered cancellation. A useful repair record captures the session ID, the last known part list, the completion attempt, the cancellation attempt, and the final storage observation. The reconciler then applies one rule: a confirmed completed object is recorded as complete, an unconfirmed session is left visible for another check, and an explicitly aborted session is never reopened by a late browser callback. That is more state than a one-request upload, but it is the state that explains why a private student file is downloadable, still uploading, or intentionally gone.
I have been paged for missed jobs and duplicate deliveries, so I put this sequence in the runbook, not in a comment nobody reads. The useful alerts are sessions past expiry, completion requests failing repeatedly, and objects whose application status does not match the recorded upload result. Your mileage may vary on thresholds; measure transfer duration and cancellation behavior before choosing them.
Storage lifecycle cleanup is a backstop. It is not a substitute for the cancel path, especially when users expect an abandoned upload to stop consuming resources quickly. Keep the application deadline shorter than the storage lifecycle window and make the difference explicit in operations documentation.
Which multipart design is suitable for private edtech uploads?
There are three reasonable shapes:
| Design | Access control | Delivery simplicity | Main trade-off |
|---|---|---|---|
| Application proxy | Centralized | Simple browser contract | Application bandwidth and connection limits become the bottleneck |
| Single presigned PUT | Application authorizes the URL | Very simple for small files | A failed large transfer usually restarts from zero |
| Multipart presigned upload | Application controls the session; storage carries parts | Resumable and efficient for large files | More state, part validation, and cleanup to operate |
For private student uploads, multipart is a good fit when files are large enough that retrying from zero is painful and the team can own a session table. It is not suitable when the product only accepts small files, cannot run cleanup, or needs a single atomic request with no client-side coordination. Stick with a single presigned PUT for the small-file path; keep the multipart path for the failure mode it actually improves.
Access control also has a boundary that is easy to miss. A presigned URL is a bearer capability for its lifetime. Keep its lifetime short, bind it to one object and one part, avoid putting sensitive data in the key, and never use an upload URL as a download URL. For downloads, authorize the current user at request time and issue a new read URL. Private means the application still makes the decision.
A production test and review checklist
Test the ugly cases first: an out-of-order part list, a duplicate part number, one part retried with a new ETag, an expired session, a completion retry after a client timeout, cancellation during completion, and a user attempting to finish another user's session. Verify that every rejected request leaves a diagnosable status.
The browser needs the storage origin's CORS policy to allow the methods and headers used by the presigned requests. The server needs request limits and content validation. The object key should be unguessable, but that is not authorization. Observability should include a session ID, user ID, object key hash, part count, and terminal transition, while avoiding raw bearer URLs in logs.
The postmortem question is simple: could the team tell which state the upload was in when the browser disappeared? If the answer is no, adding another retry loop will not fix the system. Record the state first.
References
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpuoverview.html
- https://www.backblaze.com/cloud-storage/pricing
Top comments (0)