Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upsert option to upload/update #199

Merged
merged 4 commits into from
Mar 10, 2024
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
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 @@ -368,12 +368,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 @@ -366,12 +366,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,
)