fix: add file extension to uploaded images (+ correct storage ref/URL)#263
Conversation
Extract storageUrlToPath/pathToStorageUrl in firebase.ts (reusing the existing baseStorageUrl/alternativeStorageUrl constants) instead of re-deriving the bucket URL formats inline. Drops the storageBucket non-null assertion and dedupes the URL parsing logic. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Visit the preview URL for this PR (updated for commit 964fa55):
(expires Sun, 21 Jun 2026 20:10:42 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 0c15c45ea5a4c54095387eacf30c3755c9260f22 |
uploadImage wrote objects named with a bare uuid and no extension, so sponsor/speaker/media images landed in storage without a file extension. Derive the extension from the blob MIME type (mapping the common image types, e.g. image/jpeg -> jpg, image/svg+xml -> svg) and append it to the filename. Also set the upload contentType from the blob. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes Firebase Storage upload path/URL handling for client-side image uploads by ensuring uploaded objects have proper file extensions and content types, and by converting public storage URLs to bucket-relative paths before creating refs. It also aligns returned URLs with the server’s uploadBufferToStorage format and simplifies the PDF export route to return the actual uploaded public URL.
Changes:
- Add MIME-derived file extensions and
contentTypemetadata for uploaded images; sanitizeimageFolderfrom a public URL to a storage path before buildingref(). - Introduce
storageUrlToPath()/pathToStorageUrl()helpers in the Firebase service to centralize URL↔path conversion. - Update the schedule PDF export route to return the uploaded PDF’s public URL directly.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/utils/images/uploadImage.ts |
Adds extension/contentType, fixes ref creation by converting public URL folder to bucket path, returns canonical public URL from fullPath. |
src/services/firebase.ts |
Adds shared helpers to convert between public storage URLs and bucket-relative paths. |
functions/src/api/routes/event/exportSchedulePdf.ts |
Simplifies response to return the actual uploaded PDF public URL (from uploadBufferToStorage). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Problem
Uploaded sponsor/speaker/media images landed in Firebase Storage with no file extension:
uploadImagenamed objects with a bareuuid. On top of that, the upload was broken —imageFolderarrives as a full public URL (https://storage.googleapis.com/BUCKET/events/x/) and was passed straight toref(storage, url), which Firebase only understands forgs:///firebasestorageURLs, producing a garbled ref.Changes
src/utils/images/uploadImage.tsimage/jpeg→jpg,image/svg+xml→svg, etc.), with a sane fallback. Filename is now${uuid}.${ext}.contentTypefrom the blob.imageFolder(a full public URL) to a bucket-relative path before building the ref.outputRef.fullPath, matching the server-sideuploadBufferToStorageformat.src/services/firebase.tsstorageUrlToPath()/pathToStorageUrl()helpers built on the existingbaseStorageUrl/alternativeStorageUrlconstants, instead of re-deriving the URL formats inline.Notes
uploadBufferToStorageviacheckFileTypes) and the PDF export already produce correct extensions.🤖 Generated with Claude Code