Skip to content

fix: rename cached media files to include extension when missing#22753

Merged
dcalhoun merged 1 commit intotrunkfrom
fix/media-upload-missing-file-extension
Mar 27, 2026
Merged

fix: rename cached media files to include extension when missing#22753
dcalhoun merged 1 commit intotrunkfrom
fix/media-upload-missing-file-extension

Conversation

@dcalhoun
Copy link
Copy Markdown
Member

@dcalhoun dcalhoun commented Mar 27, 2026

Description

Fix CMM-2003.

When a media file's source filename contains spaces (e.g. Samsung screenshots named screenshot_20260327_072755_one ui home5107006954197938205.jpg), Android's path resolution can produce a cached file path that ends with a trailing dot — dropping the file extension entirely.

The existing code in FluxCUtils.mediaModelFromLocalUri() already derives the correct extension from the MIME type and appends it to filename, but the on-disk file path (mFilePath) was left unchanged. Since MediaRSApiRestClient passes mFilePath to wordpress-rs, and reqwest infers the MIME type from the file extension in the path, the upload request was sent with Content-Type: application/octet-stream and a filename without an extension — causing WordPress to reject it with "Sorry, you are not allowed to upload this file type."

This PR adds a step that renames the cached file on disk to include the correct extension when the path doesn't match, keeping mFilePath consistent with mFileName.

Testing instructions

Upload a file with spaces in the filename:

  1. On a Samsung device, take a screenshot from an app like Samsung Health or One UI Home (these produce filenames with spaces)
  2. Open the WordPress/Jetpack app and navigate to Media
  3. Tap + to upload the screenshot
  • Verify the upload succeeds without errors

Alternatively, create a test file manually:

  1. Using a file manager, create or rename an image file to include spaces (e.g. test file upload.jpg)
  2. Share the file to the WordPress/Jetpack app, or upload it via the Media screen
  • Verify the upload succeeds without errors

Regression — files without spaces:

  1. Upload a media file with a normal filename (no spaces)
  • Verify the upload still succeeds as before

Path resolution can drop the file extension when the source filename
contains spaces (e.g. a Samsung screenshot named "screenshot_one ui
home123.jpg" resolves to a cached path ending in "screenshot_one ui
home123."). The existing code already derives the extension from the
MIME type and appends it to the filename, but the on-disk file path was
left unchanged. This caused downstream upload logic (wordpress-rs /
reqwest) to fail MIME type detection from the path, resulting in "not
allowed to upload this file type" errors.

Rename the cached file on disk to include the correct extension so that
the file path stored in the MediaModel is consistent with the filename.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dcalhoun dcalhoun force-pushed the fix/media-upload-missing-file-extension branch from bd628de to 23a08d6 Compare March 27, 2026 13:45
@sonarqubecloud
Copy link
Copy Markdown

@wpmobilebot
Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress Android by scanning the QR code below to install the corresponding build.

App NameWordPress Android
Build TypeDebug
Versionpr22753-23a08d6
Build Number1488
Application IDorg.wordpress.android.prealpha
Commit23a08d6
Installation URL3chic5ai59o28
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack Android by scanning the QR code below to install the corresponding build.

App NameJetpack Android
Build TypeDebug
Versionpr22753-23a08d6
Build Number1488
Application IDcom.jetpack.android.prealpha
Commit23a08d6
Installation URL4mc3ib2vmv9vo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.42%. Comparing base (9839944) to head (23a08d6).
⚠️ Report is 4 commits behind head on trunk.

Files with missing lines Patch % Lines
...in/java/org/wordpress/android/util/FluxCUtils.java 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            trunk   #22753      +/-   ##
==========================================
- Coverage   37.43%   37.42%   -0.01%     
==========================================
  Files        2320     2320              
  Lines      123589   123598       +9     
  Branches    16757    16760       +3     
==========================================
  Hits        46262    46262              
- Misses      73608    73617       +9     
  Partials     3719     3719              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dcalhoun dcalhoun marked this pull request as ready for review March 27, 2026 14:20
@dcalhoun dcalhoun requested a review from nbradbury March 27, 2026 14:20
Copy link
Copy Markdown
Contributor

@nbradbury nbradbury left a comment

Choose a reason for hiding this comment

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

Worked as described :shipit:

@dcalhoun dcalhoun merged commit 149bf6e into trunk Mar 27, 2026
27 checks passed
@dcalhoun dcalhoun deleted the fix/media-upload-missing-file-extension branch March 27, 2026 15:30
@dcalhoun dcalhoun added this to the 26.8 milestone Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants