Skip to content

Commit

Permalink
fix: add upsert option to upload/update (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
clefelhocz2 authored Mar 10, 2024
1 parent 4613502 commit db1b66a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
]

- repo: https://github.com/myint/autoflake.git
rev: v1.4
rev: v2.3.0
hooks:
- id: autoflake
args:
Expand Down
8 changes: 8 additions & 0 deletions storage3/_async/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,20 @@ async def _upload_or_update(
file_options = {}
cache_control = file_options.get("cache-control")
_data = {}
if file_options.get("upsert"):
file_options.update({"x-upsert": file_options.get("upsert")})
del file_options["upsert"]

headers = {
**self._client.headers,
**DEFAULT_FILE_OPTIONS,
**file_options,
}

# Only include x-upsert on a POST method
if method != "POST":
del headers["x-upsert"]

filename = path.rsplit("/", maxsplit=1)[-1]

if cache_control:
Expand Down
8 changes: 8 additions & 0 deletions storage3/_sync/file_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,20 @@ def _upload_or_update(
file_options = {}
cache_control = file_options.get("cache-control")
_data = {}
if file_options.get("upsert"):
file_options.update({"x-upsert": file_options.get("upsert")})
del file_options["upsert"]

headers = {
**self._client.headers,
**DEFAULT_FILE_OPTIONS,
**file_options,
}

# Only include x-upsert on a POST method
if method != "POST":
del headers["x-upsert"]

filename = path.rsplit("/", maxsplit=1)[-1]

if cache_control:
Expand Down
2 changes: 1 addition & 1 deletion storage3/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ class DownloadOptions(TypedDict, total=False):

FileOptions = TypedDict(
"FileOptions",
{"cache-control": str, "content-type": str, "x-upsert": str},
{"cache-control": str, "content-type": str, "x-upsert": str, "upsert": str},
total=False,
)

0 comments on commit db1b66a

Please sign in to comment.