supabase / storage-js

JS Client library to interact with Supabase Storage
Apache License 2.0
131 stars 40 forks source link

Can't upload metadata when uploading a file #195

Open shaaandi opened 8 months ago

shaaandi commented 8 months ago

Trying to upload some meta-data along with uploading the file and it's not working.

I am doing this

supabase.storage.from('bucket-name').upload('some-file-anme', file, {
  metadata: { ...some data }
})

I have also tried

    const fileBody = new FormData();
    fileBody.append('metadata', JSON.stringify({ name: 'data' }));
    fileBody.append('', file);
    supabase.storage.from('bucket-name').upload('some-file-anme', fileBody )

I see that it doesn't support any metadata type so please let me know how to add a metadata while uploading the file. I need the metadata for some RLS policies later.

Thanks alot.

Nuzzlet commented 2 months ago

I'm having a similar issue, but as long as I append the metadata before the file body the upload works as expected. Your second snippet actually solved this for me. I'm still not able to make the upload argument metadata object work at all.

image Inspecting the request, both metadata objects look oddly identical (you can see them both) but if I remove the custom fileBody append prior to file content, supabase does not seem to save the metadata in the DB.

I tested using fileBody append, but placing the metadata first, resulting in no saved metadata to DB.

Something probably needs to be repaired on Supabase's ingestion servers to be able to handle the metadata coming after the body.

rkristelijn commented 1 month ago

It seems storing metadata kind of works with the @supabase/storage-js@2.7.0, but only for smaller files (<45kb), but with larger files it doesn't store (you need to look into a different schema (storage) , table objects. Also there doesn't seem to be a way to get the data back out api call .info() doesn't return anything.