-
Notifications
You must be signed in to change notification settings - Fork 35
Open
Labels
enhancementNew feature or requestNew feature or request
Description
I know this is already on the list. Adding an issue to discuss what to expose exactly. Something like the following could be pushed into the provider.
We'll likely want to offer a function to get a bucket name from a record/field/file.
Further the below uses public urls which is probably not ideal but alternatives might require a SignedImageField.
We also might want to offer the opportunity to remove previous files as new ones are uploaded.
Any thoughts on all this before I carry anything further?
export const dataProvider = withLifecycleCallbacks(
supabaseDataProvider({
instanceUrl: REACT_APP_SUPABASE_URL,
apiKey: REACT_APP_SUPABASE_KEY,
supabaseClient,
}),
[
{
resource: "*", // Note * support is unreleased so we'll want to wait on that
beforeSave: async (data: any, dataProvider: any) => {
const newFiles = (
await Promise.all(
Object.keys(data)
.filter((key) => data[key]?.rawFile instanceof File)
.map((key) => [key, data[key]])
.map(async ([key, file]: any) => {
const { data, error } = await supabaseClient.storage
.from("<bucket name>")
.upload(file.rawFile.name, file.rawFile)
if (error) throw error
const path = `${REACT_APP_SUPABASE_URL}/storage/v1/object/public/<bucket name>/${data?.path}`
return { [key]: path }
})
)
).reduce((acc, val) => ({ ...acc, ...val }), {})
return { ...data, ...newFiles }
},
},
]
)
OoDeLally
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request