Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

Fix(crm): Refactor uploadToBucket for checking if file exist

Anthony Rimet75faf8118806
diff --git a/src/dataProvider.ts b/src/dataProvider.ts
index 340c79a3..14164617 100644
--- a/src/dataProvider.ts
+++ b/src/dataProvider.ts
@@ -317,18 +317,15 @@ const applyFullTextSearch = (columns: string[]) => (params: GetListParams) => {
const uploadToBucket = async (fi: RAFile) => {
if (!fi.src.startsWith('blob:') && !fi.src.startsWith('data:')) {
- const response = await fetch(
- `${import.meta.env.VITE_SUPABASE_URL}/storage/v1/object/attachments/${fi.src}`,
- {
- method: 'HEAD',
- headers: {
- authorization: import.meta.env.VITE_SUPABASE_ANON_KEY,
- },
+ // Sign URL check if path exists in the bucket
+ if (fi.path) {
+ const { error } = await supabase.storage
+ .from('attachments')
+ .createSignedUrl(fi.path, 60);
+
+ if (!error) {
+ return;
}
- );
-
- if (response.status === 200) {
- return;
}
}