From acedd4b0d08efbe767d63d969d4108e0ff7d459a Mon Sep 17 00:00:00 2001 From: Siddhant Sadangi Date: Tue, 1 Aug 2023 20:36:45 +0200 Subject: [PATCH] Update file_api.py Checking if "signedURL" exists before trying to strip "/". `cast` doesn't convert `NoneType` to `str` at runtime if there is no signedURL returned. --- storage3/_sync/file_api.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/storage3/_sync/file_api.py b/storage3/_sync/file_api.py index 90dbe77b..1ada349d 100644 --- a/storage3/_sync/file_api.py +++ b/storage3/_sync/file_api.py @@ -4,7 +4,7 @@ from dataclasses import dataclass, field from io import BufferedReader, FileIO from pathlib import Path -from typing import Any, Optional, Union, cast +from typing import Any, Optional, Union from httpx import HTTPError, Response @@ -167,9 +167,10 @@ def create_signed_url( json=json, ) data = response.json() - data[ - "signedURL" - ] = f"{self._client.base_url}{cast(str, data['signedURL']).lstrip('/')}" + if data['signedURL']: + data[ + "signedURL" + ] = f"{self._client.base_url}{str, data['signedURL'].lstrip('/')}" return data def create_signed_urls( @@ -196,9 +197,10 @@ def create_signed_urls( ) data = response.json() for item in data: - item[ - "signedURL" - ] = f"{self._client.base_url}{cast(str, item['signedURL']).lstrip('/')}" + if item['signedURL']: + item[ + "signedURL" + ] = f"{self._client.base_url}{str, item['signedURL'].lstrip('/')}" return data def get_public_url(self, path: str, options: TransformOptions = {}) -> str: