fix: resolve empty attachment MIME types from filename#9424
Conversation
Browsers on macOS often send an empty MIME type for md, csv, and txt uploads, so the API rejected allowlisted files as Invalid file type. Guess content type from the filename when the client omits it, add text/csv and tsv to the allow list, and mirror the extension fallback in the upload client helper. Fixes makeplane#9026
📝 WalkthroughWalkthroughAttachment handling now resolves missing or empty MIME types from filenames across backend upload endpoints and frontend file detection, with added support for CSV and tab-separated values plus backend unit coverage. ChangesAttachment MIME resolution
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/api/plane/settings/common.py (1)
476-477: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueDuplicate
"text/csv"entry inATTACHMENT_MIME_TYPES.
"text/csv"is now present twice in theATTACHMENT_MIME_TYPESlist (it is already listed further down in the file). Consider removing the duplicate.♻️ Proposed refactor
"text/markdown", - "text/csv", "text/tab-separated-values", "application/rtf",🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/api/plane/settings/common.py` around lines 476 - 477, Remove the newly added duplicate "text/csv" entry from ATTACHMENT_MIME_TYPES, keeping the existing occurrence elsewhere in the list and retaining "text/tab-separated-values".
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/api/plane/settings/common.py`:
- Around line 476-477: Remove the newly added duplicate "text/csv" entry from
ATTACHMENT_MIME_TYPES, keeping the existing occurrence elsewhere in the list and
retaining "text/tab-separated-values".
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a83c9704-a1a1-4a18-ab49-34c24a93bb3a
📒 Files selected for processing (7)
apps/api/plane/api/views/asset.pyapps/api/plane/api/views/issue.pyapps/api/plane/app/views/issue/attachment.pyapps/api/plane/settings/common.pyapps/api/plane/tests/unit/utils/test_attachment.pyapps/api/plane/utils/attachment.pypackages/services/src/file/helper.ts
Description
Fixes attachment uploads failing with "Invalid file type" when the browser sends an empty MIME type for text-like files (
.md,.csv,.txt), common on macOS.Allowlisted extensions were already supported, but the API required a non-empty
typeand rejectedtype: "". The client also often left type empty after signature detection (text files have no reliable magic bytes).Changes:
mimetypes+ extension fallbacks)text/csvandtext/tab-separated-valuesinATTACHMENT_MIME_TYPESfile.type, then extension mapType of Change
Test Scenarios
.md,.csv, and.txtfiles to a work item (especially from macOS) — expect success, not 400 Invalid file type"type": ""and a valid name — server guesses type and accepts if allowlistedresolve_attachment_content_typeReferences
Summary by CodeRabbit
New Features
Bug Fixes