Skip to content

Commit

Permalink
storage_image_import: if extension is missing in path get it from con…
Browse files Browse the repository at this point in the history
…tent type
  • Loading branch information
sebastienbeau committed Jul 31, 2023
1 parent 925d270 commit be768b7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion storage_image_import/models/image_relation_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ast
import base64
import logging
import mimetypes
import os
import re
import urllib
Expand Down Expand Up @@ -34,7 +35,14 @@ def _get_filename(self, headers, url):
if fname:
return fname
else:
return os.path.basename(urlparse(url).path)
fname = os.path.basename(urlparse(url).path)
if not mimetypes.guess_type(fname)[0]:
# If the fname do not content the extension
# try add it based on potential Content-Type
extention = mimetypes.guess_extension(headers["Content-Type"] or "")
if extention:
fname += extention
return fname

def _get_download_header(self):
headers = self.env["ir.config_parameter"].get_param(
Expand Down

0 comments on commit be768b7

Please sign in to comment.