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

Commit db1b66a

Browse files
authored
fix: add upsert option to upload/update (#199)
1 parent 4613502 commit db1b66a

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ repos:
2525
]
2626

2727
- repo: https://github.com/myint/autoflake.git
28-
rev: v1.4
28+
rev: v2.3.0
2929
hooks:
3030
- id: autoflake
3131
args:

storage3/_async/file_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,20 @@ async def _upload_or_update(
370370
file_options = {}
371371
cache_control = file_options.get("cache-control")
372372
_data = {}
373+
if file_options.get("upsert"):
374+
file_options.update({"x-upsert": file_options.get("upsert")})
375+
del file_options["upsert"]
373376

374377
headers = {
375378
**self._client.headers,
376379
**DEFAULT_FILE_OPTIONS,
377380
**file_options,
378381
}
382+
383+
# Only include x-upsert on a POST method
384+
if method != "POST":
385+
del headers["x-upsert"]
386+
379387
filename = path.rsplit("/", maxsplit=1)[-1]
380388

381389
if cache_control:

storage3/_sync/file_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,20 @@ def _upload_or_update(
368368
file_options = {}
369369
cache_control = file_options.get("cache-control")
370370
_data = {}
371+
if file_options.get("upsert"):
372+
file_options.update({"x-upsert": file_options.get("upsert")})
373+
del file_options["upsert"]
371374

372375
headers = {
373376
**self._client.headers,
374377
**DEFAULT_FILE_OPTIONS,
375378
**file_options,
376379
}
380+
381+
# Only include x-upsert on a POST method
382+
if method != "POST":
383+
del headers["x-upsert"]
384+
377385
filename = path.rsplit("/", maxsplit=1)[-1]
378386

379387
if cache_control:

storage3/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ class DownloadOptions(TypedDict, total=False):
7777

7878
FileOptions = TypedDict(
7979
"FileOptions",
80-
{"cache-control": str, "content-type": str, "x-upsert": str},
80+
{"cache-control": str, "content-type": str, "x-upsert": str, "upsert": str},
8181
total=False,
8282
)

0 commit comments

Comments
 (0)