Skip to content

fix: add Content-Type handling in attachment upload; update schema wi…#254

Merged
annikaholmqvist94 merged 1 commit into
mainfrom
bugFix/file-uploads-not-responding
Apr 24, 2026
Merged

fix: add Content-Type handling in attachment upload; update schema wi…#254
annikaholmqvist94 merged 1 commit into
mainfrom
bugFix/file-uploads-not-responding

Conversation

@annikaholmqvist94

@annikaholmqvist94 annikaholmqvist94 commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

…th description column migration

Closes #236

Summary by CodeRabbit

  • Bug Fixes

    • Fixed attachment upload requests to use correct content type headers for multipart form data transmission.
  • Database Changes

    • Attachment records now support an optional description field (up to 500 characters).

@coderabbitai

coderabbitai Bot commented Apr 23, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

Two targeted changes address file upload issues: the frontend API service now explicitly sets Content-Type: undefined in the Axios config for multipart form data requests to prevent incorrect content-type headers, and the database schema conditionally adds a description column to the attachment table.

Changes

Cohort / File(s) Summary
Frontend API Upload Configuration
frontend/src/services/api.jsx
Modified attachmentService.upload to explicitly pass Axios headers config with Content-Type: undefined when posting formData, ensuring proper multipart/form-data encoding instead of application/json to prevent HTTP 415 errors.
Database Schema Migration
src/main/resources/schema.sql
Added conditional ALTER TABLE statement to append description VARCHAR(500) column to the attachment table for databases created before this column was introduced.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • 45 add attachment dto #104: Adds backend DTO and entity mapping for the attachment description field, complementing the frontend upload handling and schema changes introduced in this PR.

Suggested reviewers

  • lindaeskilsson
  • johanbriger

Poem

🐰 Files now soar through the digital air,
With headers set just right with care,
Multipart forms dance without a care,
Descriptions bloom in tables fair,
Upload bugs? Gone without a prayer! 📤✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR partially addresses issue #236. Content-Type handling for multipart/form-data is fixed, but no changes to AttachmentPolicy.canUpload() logic for OWNER/VET authorization are present. Verify that AttachmentPolicy.canUpload() correctly handles OWNER (open case + own record) and VET (correct clinic) authorization branches as required by issue #236.
Out of Scope Changes check ⚠️ Warning The addition of a description column to the attachment table via schema migration is out of scope relative to issue #236, which focuses on fixing file upload failures. Either remove the unrelated description column migration or create a separate issue/PR to track this schema enhancement independently.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding Content-Type handling in attachment upload and updating the database schema with a migration.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugFix/file-uploads-not-responding

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
frontend/src/services/api.jsx (1)

93-99: Remove global Content-Type header and rely on Axios auto-detection instead of the undefined workaround.

The current 'Content-Type': undefined workaround on the upload method works in Axios 1.15.0, but it's a special-case solution. Axios automatically detects and sets Content-Type: application/json for plain object payloads and Content-Type: multipart/form-data (with correct boundary) for FormData payloads—no explicit header needed.

Removing the global 'Content-Type': 'application/json' from the axios instance and letting Axios auto-detect headers is more durable: the upload method then works without special handling, and any future multipart endpoints work automatically.

Refactor
const api = axios.create({
-    baseURL: API_BASE_URL,
-    headers: {
-        'Content-Type': 'application/json'
-    }
+    baseURL: API_BASE_URL
});
-    upload: (recordId, formData) => api.post(`/attachments/record/${recordId}`, formData, {
-        headers: { 'Content-Type': undefined }
-    }),
+    upload: (recordId, formData) => api.post(`/attachments/record/${recordId}`, formData),
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/src/services/api.jsx` around lines 93 - 99, The upload workaround
sets 'Content-Type': undefined on attachmentService.upload; instead remove the
header override here and also remove the global 'Content-Type':
'application/json' from the axios instance configuration so Axios can
auto-detect headers for FormData. Specifically, delete the headers: {
'Content-Type': undefined } override in attachmentService.upload and update the
axios instance creation (the api instance) to not set a global Content-Type so
multipart/form-data requests are handled automatically by Axios.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@frontend/src/services/api.jsx`:
- Around line 93-99: The upload workaround sets 'Content-Type': undefined on
attachmentService.upload; instead remove the header override here and also
remove the global 'Content-Type': 'application/json' from the axios instance
configuration so Axios can auto-detect headers for FormData. Specifically,
delete the headers: { 'Content-Type': undefined } override in
attachmentService.upload and update the axios instance creation (the api
instance) to not set a global Content-Type so multipart/form-data requests are
handled automatically by Axios.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0e646da0-bb49-4c5b-9756-69c3a221c259

📥 Commits

Reviewing files that changed from the base of the PR and between 2a6965b and 792dd48.

📒 Files selected for processing (2)
  • frontend/src/services/api.jsx
  • src/main/resources/schema.sql

@annikaholmqvist94
annikaholmqvist94 merged commit 85519ef into main Apr 24, 2026
2 checks passed
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.

Filuppladdning fungerar inte för OWNER och VET

1 participant