Skip to content

fix: add file extension to uploaded images (+ correct storage ref/URL)#263

Merged
HugoGresse merged 7 commits into
mainfrom
copilot/add-file-extension-to-uploaded-media
Jun 14, 2026
Merged

fix: add file extension to uploaded images (+ correct storage ref/URL)#263
HugoGresse merged 7 commits into
mainfrom
copilot/add-file-extension-to-uploaded-media

Conversation

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Uploaded sponsor/speaker/media images landed in Firebase Storage with no file extension: uploadImage named objects with a bare uuid. On top of that, the upload was broken — imageFolder arrives as a full public URL (https://storage.googleapis.com/BUCKET/events/x/) and was passed straight to ref(storage, url), which Firebase only understands for gs:// / firebasestorage URLs, producing a garbled ref.

Changes

src/utils/images/uploadImage.ts

  • Add file extension derived from the blob MIME type (image/jpegjpg, image/svg+xmlsvg, etc.), with a sane fallback. Filename is now ${uuid}.${ext}.
  • Set the upload contentType from the blob.
  • Reduce imageFolder (a full public URL) to a bucket-relative path before building the ref.
  • Return the public URL from outputRef.fullPath, matching the server-side uploadBufferToStorage format.

src/services/firebase.ts

  • Extract reusable storageUrlToPath() / pathToStorageUrl() helpers built on the existing baseStorageUrl / alternativeStorageUrl constants, instead of re-deriving the URL formats inline.

Notes

  • Only new uploads get extensions; existing stored objects are unchanged.
  • Server-side uploads (uploadBufferToStorage via checkFileTypes) and the PDF export already produce correct extensions.

🤖 Generated with Claude Code

Copilot AI linked an issue May 29, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add file extension for uploaded media files Normalize uploaded media filenames to a single detected extension May 29, 2026
Copilot AI requested a review from HugoGresse May 29, 2026 09:23
Copilot AI changed the title Normalize uploaded media filenames to a single detected extension Fix media storage paths to always end with the correct extension May 29, 2026
Copilot AI changed the title Fix media storage paths to always end with the correct extension fix: return actual public URL from PDF export instead of storage path May 29, 2026
Copilot AI changed the title fix: return actual public URL from PDF export instead of storage path fix: correct Firebase Storage ref and public URL construction in uploadImage May 29, 2026
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>
@HugoGresse HugoGresse temporarily deployed to GitHub Action PR June 14, 2026 20:03 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

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>
@HugoGresse HugoGresse deployed to GitHub Action PR June 14, 2026 20:09 — with GitHub Actions Active
@HugoGresse HugoGresse changed the title fix: correct Firebase Storage ref and public URL construction in uploadImage fix: add file extension to uploaded images (+ correct storage ref/URL) Jun 14, 2026
@HugoGresse HugoGresse marked this pull request as ready for review June 14, 2026 20:16
Copilot AI review requested due to automatic review settings June 14, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 contentType metadata for uploaded images; sanitize imageFolder from a public URL to a storage path before building ref().
  • 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.

@HugoGresse HugoGresse merged commit f01e15f into main Jun 14, 2026
6 checks passed
@HugoGresse HugoGresse deleted the copilot/add-file-extension-to-uploaded-media branch June 14, 2026 20:22
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.

Add file extension to uploaded media

3 participants