Skip to content

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

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

Merged
merged 3 commits into from
Jan 28, 2025

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
@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
@AntoLC AntoLC requested a review from lunika January 16, 2025 15:27
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch 3 times, most recently 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
Member

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
Member

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. 🙏

@lunika
Copy link
Member

lunika commented Jan 24, 2025

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

@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch 2 times, most recently from 0039c82 to e35fd8c Compare January 27, 2025 11:10
@AntoLC AntoLC requested a review from lunika January 27, 2025 11:39
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch 3 times, most recently from e2b931e to e6627dd Compare January 27, 2025 15:09
AntoLC and others added 3 commits January 28, 2025 10:24
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.
The uploaded files in the system are missing
the content-type.
We add a command to update the content-type of
the existing uploaded files.
This command will run one time when we will deploy
to the environments.
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.
@AntoLC AntoLC force-pushed the issue/add-content-type-uploaded-files branch from e6627dd to 0bfad91 Compare January 28, 2025 09:24
@AntoLC AntoLC merged commit 0d7d422 into main Jan 28, 2025
17 of 18 checks passed
@AntoLC AntoLC deleted the issue/add-content-type-uploaded-files branch January 28, 2025 09:33
@AntoLC AntoLC mentioned this pull request Jan 29, 2025
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