Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ async def list(
"""
extra_options = options or {}
extra_headers = {"Content-Type": "application/json"}
body = {**DEFAULT_SEARCH_OPTIONS, **extra_options, "prefix": path or ""}
body = {
**DEFAULT_SEARCH_OPTIONS,
**extra_options,
"prefix": path or "",
}
response = await self._request(
"POST",
f"/object/list/{self.id}",
Expand Down Expand Up @@ -196,7 +200,10 @@ async def download(self, path: str, options: TransformOptions = {}) -> bytes:
return response.content

async def upload(
self, path: str, file: Union[str, Path], file_options: Optional[dict] = None
self,
path: str,
file: Union[BufferedReader, bytes, FileIO, str, Path],
file_options: Optional[dict] = None,
) -> Response:
"""
Uploads a file to an existing bucket.
Expand All @@ -213,7 +220,11 @@ async def upload(
"""
if file_options is None:
file_options = {}
headers = {**self._client.headers, **DEFAULT_FILE_OPTIONS, **file_options}
headers = {
**self._client.headers,
**DEFAULT_FILE_OPTIONS,
**file_options,
}
filename = path.rsplit("/", maxsplit=1)[-1]

if (
Expand All @@ -225,7 +236,13 @@ async def upload(
files = {"file": (filename, file, headers.pop("content-type"))}
else:
# str or pathlib.path received
files = {"file": (filename, open(file, "rb"), headers.pop("content-type"))}
files = {
"file": (
filename,
open(file, "rb"),
headers.pop("content-type"),
)
}

_path = self._get_final_path(path)

Expand Down
5 changes: 4 additions & 1 deletion storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ def download(self, path: str, options: TransformOptions = {}) -> bytes:
return response.content

def upload(
self, path: str, file: Union[str, Path], file_options: Optional[dict] = None
self,
path: str,
file: Union[BufferedReader, bytes, FileIO, str, Path],
file_options: Optional[dict] = None,
) -> Response:
"""
Uploads a file to an existing bucket.
Expand Down