Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 844561f

Browse files
authored
fix: upload method
fix: upload fixes
2 parents 7ff6a7a + 3b9a3b3 commit 844561f

File tree

6 files changed

+73
-33
lines changed

6 files changed

+73
-33
lines changed

poetry.lock

Lines changed: 50 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

storage3/_async/file_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ async def list(
126126
Search options, including `limit`, `offset`, and `sortBy`.
127127
"""
128128
extra_options = options or {}
129-
body = dict(DEFAULT_SEARCH_OPTIONS, **extra_options)
130129
extra_headers = {"Content-Type": "application/json"}
131-
body["prefix"] = path or ""
130+
body = {**DEFAULT_SEARCH_OPTIONS, **extra_options, "prefix": path or ""}
132131
response = await self._request(
133132
"POST",
134133
f"/object/list/{self.id}",
@@ -167,13 +166,13 @@ async def upload(
167166
file
168167
The File object to be stored in the bucket. or a async generator of chunks
169168
file_options
170-
HTTP headers. For example `cacheControl`
169+
HTTP headers. For example `cache-control`
171170
"""
172171
if file_options is None:
173172
file_options = {}
174-
headers = dict(self._client.headers, **DEFAULT_FILE_OPTIONS, **file_options)
173+
headers = {**self._client.headers, **DEFAULT_FILE_OPTIONS, **file_options}
175174
filename = path.rsplit("/", maxsplit=1)[-1]
176-
files = {"file": (filename, open(file, "rb"), headers["contentType"])}
175+
files = {"file": (filename, open(file, "rb"), headers.pop("content-type"))}
177176
_path = self._get_final_path(path)
178177

179178
return await self._request(

storage3/_sync/file_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ def list(
126126
Search options, including `limit`, `offset`, and `sortBy`.
127127
"""
128128
extra_options = options or {}
129-
body = dict(DEFAULT_SEARCH_OPTIONS, **extra_options)
130129
extra_headers = {"Content-Type": "application/json"}
131-
body["prefix"] = path or ""
130+
body = {**DEFAULT_SEARCH_OPTIONS, **extra_options, "prefix": path or ""}
132131
response = self._request(
133132
"POST",
134133
f"/object/list/{self.id}",
@@ -167,13 +166,13 @@ def upload(
167166
file
168167
The File object to be stored in the bucket. or a async generator of chunks
169168
file_options
170-
HTTP headers. For example `cacheControl`
169+
HTTP headers. For example `cache-control`
171170
"""
172171
if file_options is None:
173172
file_options = {}
174-
headers = dict(self._client.headers, **DEFAULT_FILE_OPTIONS, **file_options)
173+
headers = {**self._client.headers, **DEFAULT_FILE_OPTIONS, **file_options}
175174
filename = path.rsplit("/", maxsplit=1)[-1]
176-
files = {"file": (filename, open(file, "rb"), headers["contentType"])}
175+
files = {"file": (filename, open(file, "rb"), headers.pop("content-type"))}
177176
_path = self._get_final_path(path)
178177

179178
return self._request(

storage3/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
}
99
DEFAULT_FILE_OPTIONS = {
10-
"cacheControl": "3600",
11-
"contentType": "text/plain;charset=UTF-8",
10+
"cache-control": "3600",
11+
"content-type": "text/plain;charset=UTF-8",
1212
"x-upsert": "false",
1313
}

tests/_async/test_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from time import sleep
34
from typing import TYPE_CHECKING
45
from uuid import uuid4
56

@@ -105,6 +106,7 @@ def file(tmp_path: Path, uuid_factory: Callable[[], str]) -> dict[str, str]:
105106
"bucket_folder": bucket_folder,
106107
"bucket_path": bucket_path,
107108
"mime_type": "image/svg+xml",
109+
"file_content": file_content,
108110
}
109111

110112

@@ -119,14 +121,18 @@ async def test_client_upload_file(
119121
file_name = file["name"]
120122
file_path = file["local_path"]
121123
mime_type = file["mime_type"]
124+
file_content = file["file_content"]
122125
bucket_file_path = file["bucket_path"]
123126
bucket_folder = file["bucket_folder"]
124127
options = {"content-type": mime_type}
125128

126129
await storage_file_client.upload(bucket_file_path, file_path, options)
130+
131+
sleep(3)
132+
133+
image = await storage_file_client.download(bucket_file_path)
127134
files = await storage_file_client.list(bucket_folder)
128135
image_info = next((f for f in files if f.get("name") == file_name), None)
129136

130-
assert files
131-
assert image_info is not None
137+
assert image == file_content
132138
assert image_info.get("metadata", {}).get("mimetype") == mime_type

tests/_sync/test_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def file(tmp_path: Path, uuid_factory: Callable[[], str]) -> dict[str, str]:
105105
"bucket_folder": bucket_folder,
106106
"bucket_path": bucket_path,
107107
"mime_type": "image/svg+xml",
108+
"file_content": file_content,
108109
}
109110

110111

@@ -119,14 +120,16 @@ def test_client_upload_file(
119120
file_name = file["name"]
120121
file_path = file["local_path"]
121122
mime_type = file["mime_type"]
123+
file_content = file["file_content"]
122124
bucket_file_path = file["bucket_path"]
123125
bucket_folder = file["bucket_folder"]
124126
options = {"content-type": mime_type}
125127

126128
storage_file_client.upload(bucket_file_path, file_path, options)
129+
130+
image = storage_file_client.download(bucket_file_path)
127131
files = storage_file_client.list(bucket_folder)
128132
image_info = next((f for f in files if f.get("name") == file_name), None)
129133

130-
assert files
131-
assert image_info is not None
134+
assert image == file_content
132135
assert image_info.get("metadata", {}).get("mimetype") == mime_type

0 commit comments

Comments
 (0)