Skip to content

Commit 98cbecd

Browse files
Update version to 0.19.1 and improve file upload initiation (#70)
- Bump package version to 0.19.1. - Modify the file upload initiation to include the file size in the request, enhancing the upload process. - Update validation logic to ensure the number of presigned URLs is at least equal to the expected chunk count, improving error handling during uploads.
1 parent bd0a977 commit 98cbecd

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

cytetype/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.19.0"
1+
__version__ = "0.19.1"
22

33
import requests
44

cytetype/api/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ def _upload_file(
5656
transport = HTTPTransport(base_url, auth_token)
5757

5858
# Step 1 – Initiate chunked upload
59-
_, init_data = transport.post_empty(f"upload/{file_kind}/initiate", timeout=timeout)
59+
_, init_data = transport.post_json(
60+
f"upload/{file_kind}/initiate",
61+
data={"file_size_bytes": size_bytes},
62+
timeout=timeout,
63+
)
6064
upload_id: str = init_data["upload_id"]
6165
chunk_size: int = init_data["chunk_size_bytes"]
6266

@@ -73,10 +77,10 @@ def _upload_file(
7377
r2_upload_id: str | None = init_data.get("r2_upload_id")
7478
use_r2 = presigned_urls is not None and r2_upload_id is not None
7579

76-
if use_r2 and len(presigned_urls) != n_chunks: # type: ignore[arg-type]
80+
if use_r2 and len(presigned_urls) < n_chunks: # type: ignore[arg-type]
7781
raise ValueError(
7882
f"Server returned {len(presigned_urls)} presigned URLs " # type: ignore[arg-type]
79-
f"but expected {n_chunks} (one per chunk)."
83+
f"but need at least {n_chunks} (one per chunk)."
8084
)
8185

8286
# Step 2 – Upload chunks in parallel.

0 commit comments

Comments
 (0)