diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1216405..8d20e5b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -25,7 +25,7 @@ repos: ] - repo: https://github.com/myint/autoflake.git - rev: v1.4 + rev: v2.3.0 hooks: - id: autoflake args: diff --git a/storage3/_async/file_api.py b/storage3/_async/file_api.py index 3a947eb..47f7af4 100644 --- a/storage3/_async/file_api.py +++ b/storage3/_async/file_api.py @@ -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: diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index 18aa7e0..522e3a3 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -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: diff --git a/storage3/types.py b/storage3/types.py index 9ae218f..1d9441c 100644 --- a/storage3/types.py +++ b/storage3/types.py @@ -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, )