Files, Uploads, and Storage

Treat every upload as untrusted. Keep files private, limit what you process, and check that links expire and deletes remove every copy.

Content date: October 15, 2026.

Plain English

A file feature has several parts: details about the file (who owns it), the bytes, who may read it, any processing, and deletion. An object key is a name in storage, not permission to read the object. The file name, extension, browser-declared type, and contents are all outside input. Check each one.

Use this when

Do this before you accept user files, serve private downloads, or process anything from outside your app.

If you are just starting

Allow only the file types and sizes the workflow needs. Generate your own storage names, such as random IDs. Keep private files in a private bucket (a storage container), not a public folder. Check access before upload and before every download. Test with harmless sample files.

When your project grows

Limit processing time and unpacked archive size. Re-encode images and strip their metadata. Treat a malware scan as one control, not proof a file is safe. Plan to delete across the database row, the stored object, thumbnails, and caches. A signed URL (a link with built-in, time-limited permission) works for anyone who holds it. On Amazon S3, a presigned URL also stops working when the credentials that created it expire, even if you set a longer time. Changing a user's role in your app does not cancel a link already issued, so use short lifetimes.

Worked example

A school club uploads a member-only handout to a private bucket, and the app records which club owns it. A member of another club asks for a link and is refused. A link issued to the right member stops working when its time runs out. Deleting the handout also removes the stored file and its preview image. Hiding the card on screen is not a delete.

Practice

Trace one private file through its lifecycle

  1. Pick one harmless file. List where its details, bytes, thumbnails, cache copies, and allowed readers live.
  2. Write down the allowed types and size limit, and decide whether to scan or process the file.
  3. In a test environment, try a valid file, an oversized file, a file whose type does not match its name, and a download by a user who does not own it.
  4. If your storage uses signed links, test one after it should have expired. If not, describe the access method you chose.
  5. Delete the test file. Check that its database record, stored file, and every copy on your list are gone, or note the retention rule.

Deliverable: A lifecycle map plus what you observed for upload, access, expiry, and deletion, with provider gaps marked.

Common mistakes to watch for

  • A site checks that the file ends in .jpg, so someone uploads a script renamed photo.jpg.
  • An access error appears, so someone makes the whole bucket public, and every family's permission slip becomes readable.
  • A private download link pasted into a support chat lets anyone with it open the file.
  • A tutor deletes a student's report, but only the database row goes. The file and thumbnail stay.
  • A tiny compressed archive expands to gigabytes and takes the server down.

Prompting

A weak prompt

Let users upload any file and give back a public link to it.

A better prompt

Design the smallest file workflow for [describe the task, for example parents uploading permission slips]. Define allowed types and sizes, content checks, generated names, owners, private storage, and processing limits. With harmless made-up files, test an accepted upload, rejected uploads, a wrong-user download, link expiry, and deletion of every derived copy. Tell me which behaviors depend on the storage provider and which I still need to verify.

Uploads fail where people forget to look: who may download, when links stop working, and which copies survive a delete.

Check before you move on

  • Upload size and type are limited.
  • You check file contents, not just the extension.
  • Only the right users can reach private files.
  • You tested that a signed link expires.
  • You listed every derived copy, such as thumbnails.
  • You confirmed deletion in storage, not just in the app.

You are done when

  • A test file can be reached only through the access path you intended.
  • You saw rejected uploads and a completed deletion in storage, not only on screen.

Questions to think about

Someone renames a program to photo.jpg and uploads it. Is it now an image?

No. The name is text the user chose. Check the real contents, store the file where it cannot run, and never execute uploads.

A parent deletes their child's report from the app. What might still hold a copy?

The stored file, thumbnails, cached copies, links already issued, and backups. Each needs its own removal step or a stated retention rule.

You remove a teacher's access in your app. Does a download link you gave them an hour ago stop working?

Not necessarily. A signed link carries its own permission until it expires, so keep lifetimes short and test what your provider does.

Official references