Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increasing the storage list limit beyond 100 #699

Open
nyck33 opened this issue Feb 22, 2024 · 0 comments
Open

increasing the storage list limit beyond 100 #699

nyck33 opened this issue Feb 22, 2024 · 0 comments

Comments

@nyck33
Copy link

nyck33 commented Feb 22, 2024

Rather than doing something like this:

# Function to list all files with pagination
def list_all_files(storage, bucket_name):
    offset = 0
    limit = 100  # The maximum number of files to retrieve per request
    all_files = []

    while True:
        response = storage.from_(bucket_name).list(limit=limit, offset=offset)
        files = response.data
        if files:
            all_files.extend(files)
            offset += limit
        else:
            break

    return all_files

# List all files in the bucket
all_files = list_all_files(supabase.storage, bucket_name)
print(f"Total files: {len(all_files)}")

I prefer to get a list of all file names in a bucket like

url: str = os.getenv("SUPABASE_URL")
#key: str = os.getenv("SUPABASE_SERVICE_ROLE_KEY")
key: str = os.getenv("SUPABASE_ANON_KEY")

supabase: Client = create_client(url, key)

SUPABASE_EMAIL = os.environ.get("SUPABASE_EMAIL")
SUPABASE_PASSWORD = os.environ.get("SUPABASE_PASSWORD")

# print secrets
print(SUPABASE_EMAIL, SUPABASE_PASSWORD)
my_session = supabase.auth.sign_in_with_password({"email": SUPABASE_EMAIL, "password":SUPABASE_PASSWORD})
# 

# Your storage bucket name
bucket_name = "scratch-assignments"
#%%
# List files in the bucket
files = supabase.storage.from_("scratch-assignments").list()
#%%
print(len(files)) #prints 100 but there are 104 files in the storage
#%%

That's a list of dictionaries but the contents are not that large so I'm not sure why it's set to such a low limit. Can you parameterize it like

files = supabase.storage.from_("scratch-assignments", max_ret=1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant