Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏷️(backend) add content-type to uploaded files #552

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

AntoLC
Copy link
Collaborator

@AntoLC AntoLC commented Jan 14, 2025

Purpose

All the uploaded files had the content-type set to application/octet-stream. It create issues when the file is downloaded from the frontend because the browser doesn't know how to handle the file.

image

Proposal

We improved the mimetype database and we now determine the content-type of the file and set it to the file object.

@AntoLC AntoLC added the backend label Jan 14, 2025
@AntoLC AntoLC self-assigned this Jan 14, 2025
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch 3 times, most recently from 1fcc576 to e39fab4 Compare January 14, 2025 11:23
@AntoLC AntoLC requested a review from sampaccoud January 14, 2025 11:25
Dockerfile Show resolved Hide resolved
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch 6 times, most recently from 1fa20e6 to 012af6f Compare January 15, 2025 14:58
@AntoLC AntoLC requested a review from sampaccoud January 15, 2025 15:07
@sampaccoud sampaccoud requested a review from lunika January 15, 2025 20:24
src/backend/core/api/viewsets.py Outdated Show resolved Hide resolved
src/backend/core/api/serializers.py Outdated Show resolved Hide resolved
@AntoLC AntoLC requested a review from lunika January 16, 2025 15:27
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch 2 times, most recently from 45b9fbc to 8db58c7 Compare January 20, 2025 16:20
All the uploaded files had the content-type set
to `application/octet-stream`. It create issues
when the file is downloaded from the frontend
because the browser doesn't know how to handle
the file.
We now determine the content-type of the file
and set it to the file object.
Add django-test-migrations to the project.
It is a tool that helps to test Django migrations.
The uploaded files in the system are missing
the content-type.
We add a migration to update the content-type of
the existing uploaded files.
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch from 8db58c7 to 5711bf5 Compare January 20, 2025 16:23
from django.db import migrations
from django.core.files.storage import default_storage

def fix_attachments_content_type(apps, schema_editor):
Copy link
Collaborator

Choose a reason for hiding this comment

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

All of this should be made in a management command. It is a not related to a database modification and tests should be added IMO

Copy link
Collaborator

Choose a reason for hiding this comment

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

And so we have to create a job in the helm chart to run this kind of management command. I will made it in this branch if you are ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes feel free to do it. 🙏

For a specific deployment we may need to run a specific management
command, like the one added previously updating all files content-type.
A template is added responsible to manage this case. The job will be
created only if the backend.job.command is set.
@lunika
Copy link
Collaborator

lunika commented Jan 24, 2025

@AntoLC I updated the PR accordingly with my last suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants