From c39dfad7b6ad0a8afd0b003ea496da53ba61a938 Mon Sep 17 00:00:00 2001 From: crazywoola <100913391+crazywoola@users.noreply.github.com> Date: Wed, 13 Aug 2025 22:40:06 -0700 Subject: [PATCH] fix: mime_type could be None (#23880) Co-authored-by: -LAN- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- api/factories/file_factory.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/factories/file_factory.py b/api/factories/file_factory.py index b2bcee5dc..a0ff33ab6 100644 --- a/api/factories/file_factory.py +++ b/api/factories/file_factory.py @@ -248,6 +248,8 @@ def _get_remote_file_info(url: str): # Initialize mime_type from filename as fallback mime_type, _ = mimetypes.guess_type(filename) + if mime_type is None: + mime_type = "" resp = ssrf_proxy.head(url, follow_redirects=True) resp = cast(httpx.Response, resp) @@ -256,7 +258,12 @@ def _get_remote_file_info(url: str): filename = str(content_disposition.split("filename=")[-1].strip('"')) # Re-guess mime_type from updated filename mime_type, _ = mimetypes.guess_type(filename) + if mime_type is None: + mime_type = "" file_size = int(resp.headers.get("Content-Length", file_size)) + # Fallback to Content-Type header if mime_type is still empty + if not mime_type: + mime_type = resp.headers.get("Content-Type", "").split(";")[0].strip() return mime_type, filename, file_size