Skip to main content
Features

File storage

Upload avatars and organization logos to private S3-compatible storage.

Open MarkdownFull AI corpusFeedback

Configure a bucket

The kit supports S3-compatible storage, including Cloudflare R2. Set the bucket name in NEXT_PUBLIC_IMAGES_BUCKET_NAME and configure S3_ENDPOINT, S3_REGION, S3_ACCESS_KEY_ID and S3_SECRET_ACCESS_KEY on the server.

Use credentials restricted to the bucket operations your application needs. Never put storage credentials in a NEXT_PUBLIC_ or VITE_ variable, commit them to Git or return them to the browser.

Included upload flow

The profile-avatar and organization-logo controls use the existing crop dialog, then post the cropped image to /api/storage/upload. The application server writes the object to the configured bucket with its S3 credentials.

The server checks:

  • A trusted request origin and an authenticated session.
  • The account that rendered the calling page.
  • The intended active organization and an owner or admin role for logo uploads.
  • A PNG or JPEG content type matching the file signature.
  • A nonempty body no larger than 2 MB, enforced while reading the body as well as from its declared length.

Object keys are generated on the server. The caller cannot choose another user's object path or an arbitrary bucket. Upload requests and provider calls have deadlines.

CORS and shared demo buckets

The included uploads go to the application's own origin, not directly from the browser to S3. They therefore do not require a bucket CORS policy. An existing compatible bucket can be reused without adding another browser origin to its CORS rules.

If you build a separate direct-to-bucket upload flow, configure that flow's CORS, content validation and permissions independently. Do not open the bucket publicly or allow all origins just to bypass an upload error.

Image delivery

The bucket itself stays private. The /storage/ route redirects image reads to temporary presigned download URLs. The UI's useStorage hook and avatar/logo components handle those paths.

Profile pictures and organization logos are display assets. For confidential files, add an authorization check to the download path and use a separate storage policy rather than assuming an unguessable image URL is sufficient.

See README_STORAGE.md in your repository for the source entry points.