© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
Gabox

Upload file using python supabase client

Hello, I am trying supabase for the first time with fastAPI and really enjoying the project. However, I am struggling with figuring out how to upload a file using the supabage python storage client.

My function takes a an Excel file, converts it to a Pandas dataframe to perform some operations and they it should upload to Supabase storage.

This is my current function:
@app.post("/uploadfile/")
def create_upload_file(file: UploadFile = File(...)):
    """
    Uploads a file to an existing bucket.
    Parameters
    ----------
    path
        The relative file path including the bucket ID. Should be of the format `bucket/folder/subfolder/filename.png`.
    file
        The File object to be stored in the bucket. or a async generator of chunks
    file_options
        HTTP headers. For example `cache-control`
    """

    print (file.filename)

    contents = file.file.read()
    buffer = BytesIO(contents)

    df = pd.read_excel(buffer)
    df.fillna('', inplace=True)

    buffer.close()
    file.file.close()

    print (df)

    # Do operations with df, all good up to this point
    for index, row in df.iterrows():
        # print(row["id"], "|", row["title"], "|", count, "|", row["state"], sep="")
        print (row["Column4"])

    #Save the dataframe as excel file in memory
    in_memory_fp = io.BytesIO()
    df.to_excel(in_memory_fp, index=False)
    in_memory_fp.seek(0,0)
    # pd.testing.assert_frame_equal(df, pd.read_excel(in_memory_fp))

    actual_file = in_memory_fp.read()

    print (isinstance(in_memory_fp, BufferedReader))
    print (isinstance(in_memory_fp, bytes))
    print (isinstance(in_memory_fp, FileIO))

    print (isinstance(actual_file, BufferedReader))
    print (isinstance(actual_file, bytes))
    print (isinstance(actual_file, FileIO))

      
    supabase.storage().StorageFileAPI("tripcase-results").upload("tripcase-results/supabase.xlsx",actual_file)

    return {"filename": file.filename}
@app.post("/uploadfile/")
def create_upload_file(file: UploadFile = File(...)):
    """
    Uploads a file to an existing bucket.
    Parameters
    ----------
    path
        The relative file path including the bucket ID. Should be of the format `bucket/folder/subfolder/filename.png`.
    file
        The File object to be stored in the bucket. or a async generator of chunks
    file_options
        HTTP headers. For example `cache-control`
    """

    print (file.filename)

    contents = file.file.read()
    buffer = BytesIO(contents)

    df = pd.read_excel(buffer)
    df.fillna('', inplace=True)

    buffer.close()
    file.file.close()

    print (df)

    # Do operations with df, all good up to this point
    for index, row in df.iterrows():
        # print(row["id"], "|", row["title"], "|", count, "|", row["state"], sep="")
        print (row["Column4"])

    #Save the dataframe as excel file in memory
    in_memory_fp = io.BytesIO()
    df.to_excel(in_memory_fp, index=False)
    in_memory_fp.seek(0,0)
    # pd.testing.assert_frame_equal(df, pd.read_excel(in_memory_fp))

    actual_file = in_memory_fp.read()

    print (isinstance(in_memory_fp, BufferedReader))
    print (isinstance(in_memory_fp, bytes))
    print (isinstance(in_memory_fp, FileIO))

    print (isinstance(actual_file, BufferedReader))
    print (isinstance(actual_file, bytes))
    print (isinstance(actual_file, FileIO))

      
    supabase.storage().StorageFileAPI("tripcase-results").upload("tripcase-results/supabase.xlsx",actual_file)

    return {"filename": file.filename}
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

.rpc() with python supabase-client
SupabaseSSupabase / help-and-questions
4y ago
Upload file with expiration using the browser client
SupabaseSSupabase / help-and-questions
2mo ago
Supabase Storage file upload - 403 Unauthorized
SupabaseSSupabase / help-and-questions
7mo ago
How to upload a file to Supabase storage using Nodejs.
SupabaseSSupabase / help-and-questions
3y ago