Skip to content

Commit 142a52a

Browse files
committed
extract mimetype and include in upload metadata
1 parent ad066b0 commit 142a52a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/bma_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import exifread
1414
import httpx
15+
import magic
1516
from PIL import Image, ImageOps
1617

1718
logger = logging.getLogger("bma_client")
@@ -149,6 +150,9 @@ def upload_file(self, path: Path, attribution: str, file_license: str) -> dict[s
149150
)
150151
width, height = rotated.size
151152

153+
with path.open("rb") as fh:
154+
mimetype = magic.from_buffer(fh.read(2048), mime=True)
155+
152156
# open file
153157
with path.open("rb") as fh:
154158
files = {"f": (path.name, fh)}
@@ -158,6 +162,7 @@ def upload_file(self, path: Path, attribution: str, file_license: str) -> dict[s
158162
"license": file_license,
159163
"width": width,
160164
"height": height,
165+
"mimetype": mimetype,
161166
}
162167
# doit
163168
r = self.client.post(

0 commit comments

Comments
 (0)