From a96a6ebf5d96235f670ab6cf6ea42d69b1400be7 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Tue, 7 Jan 2025 18:09:25 -0500 Subject: [PATCH] Minor improvement to the saving of a hosted file. Guessing the content type based on the extension. --- app/methods/hosted_file_methods.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/methods/hosted_file_methods.py b/app/methods/hosted_file_methods.py index e5c4031..32c712b 100644 --- a/app/methods/hosted_file_methods.py +++ b/app/methods/hosted_file_methods.py @@ -1,4 +1,4 @@ -import datetime, hashlib, os, pathlib, shutil, time +import datetime, hashlib, mimetypes, os, pathlib, shutil, time from fastapi import File, UploadFile from typing import Dict, List, Optional, Set, Union @@ -441,8 +441,7 @@ async def save_file_to_hosted_file( # There is a difference between Content-Type and MIME type. # https://stackoverflow.com/questions/3452381/whats-the-difference-of-contenttype-and-mimetype - # file_info['content_type'] = file.content_type # might also include charset or other parameters - # file_info['mimetype'] = file.mimetype # This may need to be filled in a different way? + file_info['content_type'] = mimetypes.guess_type(filename)[0] file_obj.seek(0, os.SEEK_END) file_size = file_obj.tell()