-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: get file extension from key #544
Conversation
jrcastro2
commented
Nov 10, 2023
•
edited
Loading
edited
- closes https://github.com/zenodo/rdm-project/issues/547
95c3c6a
to
09e6c53
Compare
@@ -177,7 +178,9 @@ def dumps(self): | |||
@property | |||
def ext(self): | |||
"""File extension.""" | |||
ext = mimetypes.guess_extension(self.object_model.mimetype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# The ``ext`` property is used to in search to aggregate file types and we want e.g. both ``.jpeg`` and ``.jpg`` to be aggregated under ``.jpg``
ext = mimetypes.guess_extension(self.object_model.mimetype)
if ext is not None:
return ext[1:]
# Support non-standard file extensions that cannot be guessed
_, ext = os.path.splitext(self.key)
if ext and len(ext) <= 5:
return ext.lower()
return None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the clarification.
However to make this work we would also need to change this to not return "application/octet-stream". I will do the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided not to remove the fallback mimetype as it might cause issues on files serving, instead we check if the mimetype is set to the fallback to try to get the extenstion from the filename or not.
2df0478
to
4c8ed3c
Compare
4c8ed3c
to
d24b872
Compare
d24b872
to
8b7d597
Compare