
Summary
Key points of this document
- Where are the design challenges?
- How to define boundaries
- Details that matter in implementation
Overview
Uploaded files are an area more prone to public exposure incidents than DB records. It's necessary to design not just what can be saved, but also who can see it, when it's deleted, and how long links are valid. In file upload design, it's more important to be able to explain later who can read a file, when, and for what reason, rather than just being able to save it.
Where are the design challenges?
If public URLs are saved as-is to quickly implement file uploads, paths accessible without authentication remain. Even if you try to make them private later, handling existing URLs, caches, and external sharing becomes problematic.
Files are used in multiple ways, such as image previews, PDF downloads, administrator verification, and user self-retrieval. Streaming everything through the app increases load, and making everything a public URL weakens permission management.
Even if uploaded files differ in format (e.g., images, PDFs, CSVs), issues arise in business operations regarding permissions, retention periods, virus checks, previews, and deletion handling. An implementation that merely places files in storage is prone to accidental public exposure or forgotten deletions.
How to define boundaries
The file body is placed in a private area of GCS or S3, and the app DB stores the owner, purpose, MIME type, size, storage path, and status. When viewing, the app checks permissions and issues a signed URL valid for a short period.
In the design, the file body is placed in a private GCS or S3 bucket, and the app DB stores the owner, purpose, MIME, size, hash, status, and retention period. Only when a user views it, after permission confirmation, a short-lived signed URL is issued.
Details that matter in implementation
For uploads, choose between via-app or signed upload URL based on file size and UI requirements. After saving, validate MIME type, extension, and size limit, and if necessary, perform virus scans or image conversions asynchronously.
Uploads are divided into the sequence of reservation record creation, signed URL issuance, direct upload from client, completion notification, verification, and availability. Maintaining DB states like pending, uploaded, verified, available, deleted makes it easier to handle mid-process failures and retries.
- Do not use original filenames for object keys; instead, use unguessable IDs and purpose-specific prefixes.
- When downloading, verify DB permissions before issuing a signed URL, and do not store the URL itself long-term.
- Prepare an orphaned file detection job in case DB deletion and storage deletion get out of sync.
Observe how it breaks
During verification, confirm that unauthorized users cannot guess and retrieve URLs, expired URLs cannot be used, and storage is cleaned up after DB record deletion. Also check list display performance for large numbers of files.
During verification, confirm that unauthorized users cannot obtain URLs, expired URLs cannot be used, and files that failed during upload do not become available. Large files, extension spoofing, and MIME mismatches are also test targets.
Discarded options and trade-offs
Signed URLs are convenient, but anyone who knows the URL can access it for a short period after issuance. For extremely sensitive files, it may be more appropriate to deliver them via the app, authenticating each time.
The signed URL method reduces the load on the app server, but state management becomes complex. Delivering all files via the app simplifies control but introduces capacity and speed constraints. A decision is needed to separate methods based on file size and sensitivity.
Decision criteria for practical application
File management is not just a feature of the upload screen. By designing the integrity of private storage, permission checks, time-limited delivery, and deletion as a set, the risk of information exposure in business applications can be reduced.
In private storage design, merely hiding URLs is not enough. Linking permissions, status, and retention periods in the DB with the actual entities in storage forms the foundation for secure file operations.


