Skip to content

Commit

Permalink
Set content-type during upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Sep 30, 2024
1 parent 1005c6b commit 92282f6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion audbackend/core/backend/minio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import mimetypes
import os
import tempfile
import typing
Expand Down Expand Up @@ -369,7 +370,13 @@ def _put_file(
)
print(desc, end="\r")

self._client.fput_object(self.repository, dst_path, src_path)
content_type = mimetypes.guess_type(src_path)[0] or "application/octet-stream"
self._client.fput_object(
self.repository,
dst_path,
src_path,
content_type=content_type,
)

if verbose: # pragma: no cover
# Clear progress line
Expand Down
27 changes: 27 additions & 0 deletions tests/test_backend_minio.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ def test_authentication(tmpdir, hosts, hide_credentials):
backend.open()


@pytest.mark.parametrize(
"interface",
[(audbackend.backend.Minio, audbackend.interface.Unversioned)],
indirect=True,
)
@pytest.mark.parametrize(
"path, expected,",
[
("/text.txt", "text/plain"),
],
)
def test_content_type(tmpdir, interface, path, expected):
r"""Test setting of content type.
Args:
tmpdir: tmpdir fixture
interface: interface fixture
path: path of file on backend
expected: expected content type
"""
tmp_path = audeer.touch(audeer.path(tmpdir, path[1:]))
interface.put_file(tmp_path, path)
stats = interface._backend._client.stat_object(interface.repository, path)
assert stats.content_type == expected


@pytest.mark.parametrize(
"interface",
[(audbackend.backend.Minio, audbackend.interface.Unversioned)],
Expand Down

0 comments on commit 92282f6

Please sign in to comment.