From 150ebbecb906046792aab4b5a58b37ff856212ca Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Fri, 28 Feb 2025 02:51:10 +0200 Subject: [PATCH] feat: support object lifecycle with gcs cdn --- projects/fal/src/fal/toolkit/file/providers/fal.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/projects/fal/src/fal/toolkit/file/providers/fal.py b/projects/fal/src/fal/toolkit/file/providers/fal.py index 4eecf4bb..0da0aeec 100644 --- a/projects/fal/src/fal/toolkit/file/providers/fal.py +++ b/projects/fal/src/fal/toolkit/file/providers/fal.py @@ -125,7 +125,9 @@ def set(self, value: VariableType) -> None: @dataclass class FalFileRepositoryBase(FileRepository): @retry(max_retries=3, base_delay=1, backoff_type="exponential", jitter=True) - def _save(self, file: FileData, storage_type: str) -> str: + def _save( + self, file: FileData, storage_type: str, headers: dict[str, str] | None = None + ) -> str: key_creds = key_credentials() if not key_creds: raise FileUploadException("FAL_KEY must be set") @@ -135,6 +137,7 @@ def _save(self, file: FileData, storage_type: str) -> str: "Authorization": f"Key {key_id}:{key_secret}", "Accept": "application/json", "Content-Type": "application/json", + **(headers or {}), } grpc_host = os.environ.get("FAL_HOST", "api.alpha.fal.ai") @@ -193,7 +196,11 @@ def save( multipart_max_concurrency: int | None = None, object_lifecycle_preference: dict[str, str] | None = None, ) -> str: - return self._save(file, "gcs") + headers = {} + if object_lifecycle_preference: + headers["X-Fal-Object-Lifecycle"] = json.dumps(object_lifecycle_preference) + + return self._save(file, "gcs", headers=headers) class MultipartUpload: