[utils] `urlhandle_detect_ext`: Use `x-amz-meta-file-type` headers (#13749)

Authored by: bashonly
pull/13351/head^2
bashonly 1 week ago committed by GitHub
parent b8abd255e4
commit 28bf46b7da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3106,21 +3106,15 @@ def get_compatible_ext(*, vcodecs, acodecs, vexts, aexts, preferences=None):
def urlhandle_detect_ext(url_handle, default=NO_DEFAULT): def urlhandle_detect_ext(url_handle, default=NO_DEFAULT):
getheader = url_handle.headers.get getheader = url_handle.headers.get
cd = getheader('Content-Disposition') if cd := getheader('Content-Disposition'):
if cd: if m := re.match(r'attachment;\s*filename="(?P<filename>[^"]+)"', cd):
m = re.match(r'attachment;\s*filename="(?P<filename>[^"]+)"', cd) if ext := determine_ext(m.group('filename'), default_ext=None):
if m: return ext
e = determine_ext(m.group('filename'), default_ext=None)
if e:
return e
meta_ext = getheader('x-amz-meta-name')
if meta_ext:
e = meta_ext.rpartition('.')[2]
if e:
return e
return mimetype2ext(getheader('Content-Type'), default=default) return (
determine_ext(getheader('x-amz-meta-name'), default_ext=None)
or getheader('x-amz-meta-file-type')
or mimetype2ext(getheader('Content-Type'), default=default))
def encode_data_uri(data, mime_type): def encode_data_uri(data, mime_type):

Loading…
Cancel
Save