From d42295eb62082b2c369eef3b00ed5ae5444199ce Mon Sep 17 00:00:00 2001 From: Tobias Herber <22559657+herber@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:31:08 +0100 Subject: [PATCH 1/2] Add direct upload headers --- src/metorial/_file_upload.py | 11 ++++++++--- tests/test_file_upload.py | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/metorial/_file_upload.py b/src/metorial/_file_upload.py index 850c673c..22ab3c36 100644 --- a/src/metorial/_file_upload.py +++ b/src/metorial/_file_upload.py @@ -6,7 +6,7 @@ from collections.abc import Iterator from contextlib import contextmanager from dataclasses import dataclass -from typing import IO, Any, Union +from typing import IO, Any, Dict, Optional, Union import requests @@ -118,7 +118,9 @@ def _upload_with_url( } ) - _put_to_storage(upload.get("method") or "PUT", upload["url"], source) + _put_to_storage( + upload.get("method") or "PUT", upload["url"], source, upload.get("headers") or {} + ) complete: dict[str, Any] = {"mode": "complete", "file_upload_id": session["id"]} if instance_id is not None: @@ -126,7 +128,9 @@ def _upload_with_url( return manager._request("POST", MetorialRequest(path=["files"], body=complete)) -def _put_to_storage(method: str, url: str, source: _Source) -> None: +def _put_to_storage( + method: str, url: str, source: _Source, extra_headers: Optional[Dict[str, str]] = None +) -> None: # The URL signature covers the content type, so it must match the declared # file_type, and Metorial credentials must not be sent to the storage backend. try: @@ -135,6 +139,7 @@ def _put_to_storage(method: str, url: str, source: _Source) -> None: url, data=source.stream, headers={ + **(extra_headers or {}), "Content-Type": source.content_type, "Content-Length": str(source.size), }, diff --git a/tests/test_file_upload.py b/tests/test_file_upload.py index 626abba9..267b3910 100644 --- a/tests/test_file_upload.py +++ b/tests/test_file_upload.py @@ -76,7 +76,11 @@ def handle(self, handler: BaseHTTPRequestHandler) -> None: { "object": "file_upload", "id": "fup_1", - "upload": {"url": f"http://{host}/storage", "method": "PUT"}, + "upload": { + "url": f"http://{host}/storage", + "method": "PUT", + "headers": {"x-ms-blob-type": "BlockBlob"}, + }, }, ) else: @@ -235,6 +239,7 @@ def test_large_files_use_an_upload_url( assert put["method"] == "PUT" assert put["body"] == b"large contents" assert put["headers"]["Content-Type"] == "application/octet-stream" + assert put["headers"]["x-ms-blob-type"] == "BlockBlob" assert "Authorization" not in put["headers"] assert complete["json"] == { "mode": "complete", From 3c5507351365772733f2d2e3b7d7c1bdd002d4b3 Mon Sep 17 00:00:00 2001 From: Tobias Herber <22559657+herber@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:33:47 +0100 Subject: [PATCH 2/2] Fix formatting --- src/metorial/_file_upload.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/metorial/_file_upload.py b/src/metorial/_file_upload.py index 22ab3c36..472e2e4a 100644 --- a/src/metorial/_file_upload.py +++ b/src/metorial/_file_upload.py @@ -6,7 +6,7 @@ from collections.abc import Iterator from contextlib import contextmanager from dataclasses import dataclass -from typing import IO, Any, Dict, Optional, Union +from typing import IO, Any, Union import requests @@ -129,7 +129,7 @@ def _upload_with_url( def _put_to_storage( - method: str, url: str, source: _Source, extra_headers: Optional[Dict[str, str]] = None + method: str, url: str, source: _Source, extra_headers: dict[str, str] | None = None ) -> None: # The URL signature covers the content type, so it must match the declared # file_type, and Metorial credentials must not be sent to the storage backend.