from django.core.files.storage import DefaultStorage
from django.http import HttpRequest, HttpResponse


def view_file_download(request: HttpRequest) -> HttpResponse:
    """
    Serve a media file like a download.

    Args:
        request: HTTP request.

    Returns:
        Media file as an attachment to download.

    """
    storage = DefaultStorage()  # Objet capable de manipuler des fichiers média
    with storage.open("django-upload.jpg", "rb") as file:  # relative to MEDIA_ROOT
        response = HttpResponse(file, content_type="image/jpeg")
        # Use list notation to set headers
        response["Content-Disposition"] = "attachment; filename=django-upload.jpg"
        return response
