Changelog

Browser uploads to Storage

A browser can now upload straight to a Storage bucket through a signed URL, without the file passing through your backend. Name the origins that may upload:

alien.ts
const uploads = new alien.Storage("uploads")
  .corsUploadOrigins(["https://app.acme.com"])
  .build()

Your backend signs a PUT URL, and the page uploads to it:

src/upload.ts
const upload = await storage("uploads").signedUrl({
  method: "PUT",
  path: `avatars/${userId}.png`,
  expiresIn: 900,
})
// Send upload.url, upload.method and upload.headers to the page.
app/upload.ts
await fetch(upload.url, { method: upload.method, headers: upload.headers, body: file })

Alien adds an upload CORS rule next to the read rule from .corsAllowedOrigins(), with the headers each cloud's signed uploads send.

  • Clouds: AWS, Google Cloud, and Azure, in every setup method
  • Single-request uploads only: a presigned or SAS URL, or one multipart part. Uploads that start with a POST aren't covered
  • Checked at build: an origin a browser would never send is refused with STORAGE_CORS_INVALID

Read the docs →