Skip to content

Commit

Permalink
Always seek the file before reading it
Browse files Browse the repository at this point in the history
  • Loading branch information
0ssigeno committed Dec 10, 2024
1 parent 77b9416 commit 155969f
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions api_app/serializers/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,11 @@ def validate(self, attrs: dict) -> dict:
# calculate ``file_mimetype``
if "file_name" not in attrs:
attrs["file_name"] = attrs["file"].name
attrs["file_mimetype"] = MimeTypes.calculate(
attrs["file"].read(), attrs["file_name"]
)
# calculate ``md5``
file_obj = attrs["file"].file
file_obj.seek(0)
file_buffer = file_obj.read()
attrs["file_mimetype"] = MimeTypes.calculate(file_buffer, attrs["file_name"])
attrs["md5"] = calculate_md5(file_buffer)
attrs = super().validate(attrs)
logger.debug(f"after attrs: {attrs}")
Expand Down

0 comments on commit 155969f

Please # to comment.