Not even sure but I'm sure it's better
This commit is contained in:
@ -9,11 +9,11 @@ export const useFileUpload = () => {
|
||||
const uploadToStorage = async (file: File, bucket: string) => {
|
||||
try {
|
||||
setIsUploading(true);
|
||||
|
||||
|
||||
// Generate a unique filename to avoid collisions
|
||||
const fileExt = file.name.split('.').pop();
|
||||
const fileName = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}.${fileExt}`;
|
||||
|
||||
|
||||
// Upload the file to Supabase storage
|
||||
const uploadResult = await uploadFile({
|
||||
bucket,
|
||||
@ -24,15 +24,19 @@ export const useFileUpload = () => {
|
||||
contentType: file.type,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!uploadResult.success) {
|
||||
throw new Error(uploadResult.error || `Failed to upload to ${bucket}`);
|
||||
}
|
||||
|
||||
|
||||
return { success: true, path: uploadResult.data };
|
||||
} catch (error) {
|
||||
console.error(`Error uploading to ${bucket}:`, error);
|
||||
toast.error(error instanceof Error ? error.message : `Failed to upload to ${bucket}`);
|
||||
toast.error(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: `Failed to upload to ${bucket}`,
|
||||
);
|
||||
return { success: false, error };
|
||||
} finally {
|
||||
setIsUploading(false);
|
||||
@ -46,4 +50,4 @@ export const useFileUpload = () => {
|
||||
fileInputRef,
|
||||
uploadToStorage,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user