Skip to content

Fix: Correctly generate thumbnail URLs for path-style and virtual-hosted S3 providers #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lukmay
Copy link

@lukmay lukmay commented Jul 2, 2025

This PR resolves an issue where image thumbnails fail to load when using a self-hosted, S3-compatible object storage provider with a public custom domain. The fix updates the thumbnail generation logic to correctly handle both path-style and virtual-hosted (subdomain) style URLs based on environment variables.

The Problem

When self-hosting with an S3-compatible provider that uses a public custom domain (e.g., Cloudflare R2), the /api/thumbnail endpoint was not correctly using the public URL from the CAP_AWS_BUCKET_URL environment variable. Instead, it would fall back to generating pre-signed URLs or incorrect raw URLs, causing the upstream image fetch by the Next.js server to fail with a 404 Not Found error.

This resulted in broken image thumbnails across the dashboard:

image

The Solution

The /api/thumbnail/route.ts file has been updated to implement more robust URL generation logic:

  • The API route now uses the S3_PATH_STYLE environment variable as a switch to determine the correct URL structure.
  • If S3_PATH_STYLE is true (for providers like MinIO), it constructs a path-style URL: http://<endpoint>/<bucket>/<key>.
  • If S3_PATH_STYLE is false (for providers like Cloudflare R2), it constructs a virtual-hosted style URL using the public CAP_AWS_BUCKET_URL: https://<custom_domain_url>/<key>.
  • This ensures the correct public URL is always used when a custom storage configuration is provided, making the application compatible with a wider range of self-hosting setups.

How to Test

  1. Configure a self-hosted environment using an S3-compatible provider and a public custom domain.
  2. Set the S3_PATH_STYLE and CAP_AWS_BUCKET_URL environment variables according to your provider's requirements.
  3. Build the Docker image with this code change.
  4. Launch the application and upload a new video.
  5. Verify that the video thumbnail loads correctly and that there are no 404 errors related to image fetching.

This change significantly improves the self-hosting experience for a wider range of S3-compatible storage providers. Thank you for considering this contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant