supabase / storage-py

Home Page:https://supabase-community.github.io/storage-py/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

An error occurred: 'SyncStorageClient' object is not callable

amzu-dev opened this issue · comments

Hi, My code is as below and I get this error:

An error occurred: 'SyncStorageClient' object is not callable
Code:
`def check_and_upload_file(bucket_name: str, file_name: str, file_content):
try:

    # Upload the file, automatically overwriting if it exists
    supabase: Client = create_client(url, key)
    storage = supabase.storage().StorageFileAPI(bucket_name)
    upload_response = supabase.storage.from_(bucket_name).upload(file_name,
                                                                 file_content,
                                                                 {"upsert": True, "cacheControl": "3600",
                                                                  "contentType": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"})

    if upload_response.status_code in [200, 201]:
        if upload_response.status_code in [200, 201]:
            print("File uploaded/overwritten successfully:", file_name)
        else:
            print("Failed to upload file:", upload_response.json())
            return ""

        # Generate a signed URL for accessing the private file
        signed_url_response = storage.create_signed_url(file_name, expires_in=None)  # URL expires in 60 seconds
        if signed_url_response.status_code == 200:
            signed_url = signed_url_response.json()["signedURL"]
            # Construct the full URL to access the file
            full_url = f"{signed_url}"
            return full_url
        else:
            print("Failed to generate signed URL:", signed_url_response.json())
            return ""
except Exception as e:
    print(e.with_traceback(None))
    print(f"An error occurred: {e}")
    return ""

`

I am new to supabase, so any help is much appreciated.

You code doesn't look correct. You have this line

supabase.storage().StorageFileAPI(bucket_name)

which is not a part of the API for this library. Please take a look at the docs to see the usage of this library.

Closing this out as there hasn't been any reply in over a month.