supabase / storage-py

https://supabase-community.github.io/storage-py/
MIT License
44 stars 18 forks source link

An error occurred: 'SyncStorageClient' object is not callable #207

Closed amzu-dev closed 6 months ago

amzu-dev commented 8 months ago

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.

silentworks commented 7 months ago

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.

silentworks commented 6 months ago

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