Overview
Learn how the shipped S3-compatible image storage flow works.
The Pro Next.js Prisma kit ships a focused image storage flow for avatars and organization logos. Both Pro kits use the same storage implementation.
Upload flow
- A signed-in user selects and crops an image in the browser.
- The client calls
storage.signedUploadUrlwith an object key and the configured images bucket. - The protected tRPC procedure checks only that the bucket equals
storageConfig.bucketNames.images. getSignedUploadUrlvalidates the key syntax and returns aPutObjectURL that expires after 60 seconds.- The browser uploads directly to the storage provider.
- Better Auth stores the object key in the user
imagefield or organizationlogofield.
The server does not create an ownership record for the object. It also does not derive the key from the authenticated user, enforce a size limit or inspect the uploaded bytes.
Read flow
useStorage(image)returns/storage/{imagesBucket}/{image}for a local image key.- The public route reads the bucket and image key from the URL.
- If the bucket matches the configured images bucket, it returns a redirect to a signed
GetObjectURL. - The signed URL and redirect cache both use a one-hour lifetime.
The route does not read the current session. It does not query the database or verify ownership. This is suitable for product images that are intended to be displayed wherever their key is known, not for confidential files.
Use a single path segment for shipped images
The upload signer accepts keys containing slashes, but the current read route
destructures only the bucket and the first segment after it. Avatar and logo
keys must therefore be flat, such as 550e8400.png. If you need
nested keys such as users/123/avatar.png, update the route to
join all remaining path segments before requesting the object.
Included functions
getSignedUploadUrl(path, bucket); // PutObject URL, 60 seconds
getSignedUrl(path, bucket, expiresIn); // GetObject URLBoth functions validate that a path:
- Is not absolute
- Contains no
.., null byte or hidden path segment - Uses only letters, numbers, hyphens, underscores, slashes and dots
Path validation prevents malformed object keys. It is not a user or organization authorization check.
Current scope
| Capability | Shipped behavior |
|---|---|
| Avatar and logo upload | Included |
| Direct browser upload | Included |
| Authenticated upload signing | Included |
| Public image redirect | Included |
| Private file authorization | Not included |
| File ownership metadata | Not included |
| Listing and deletion APIs | Not included |
| Storage quota enforcement | Not included |
| Nested-key download routing | Not included |
Use the included integration as a starting point for public display images. Build a separate authorized download flow for private files.