Fix: Correctly generate thumbnail URLs for path-style and virtual-hosted S3 providers #712
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theCAP_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 a404 Not Found
error.This resulted in broken image thumbnails across the dashboard:
The Solution
The
/api/thumbnail/route.ts
file has been updated to implement more robust URL generation logic:S3_PATH_STYLE
environment variable as a switch to determine the correct URL structure.S3_PATH_STYLE
istrue
(for providers like MinIO), it constructs a path-style URL:http://<endpoint>/<bucket>/<key>
.S3_PATH_STYLE
isfalse
(for providers like Cloudflare R2), it constructs a virtual-hosted style URL using the publicCAP_AWS_BUCKET_URL
:https://<custom_domain_url>/<key>
.How to Test
S3_PATH_STYLE
andCAP_AWS_BUCKET_URL
environment variables according to your provider's requirements.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.