Add default metadata & make replaceFile function
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useRef } from 'react';
|
||||
import { deleteFile, uploadFile } from '@/lib/actions';
|
||||
import { deleteFile, replaceFile, uploadFile } from '@/lib/actions';
|
||||
import { toast } from 'sonner';
|
||||
import { useAuth } from '@/components/context/auth';
|
||||
import { resizeImage } from '@/lib/hooks';
|
||||
@ -43,6 +43,21 @@ export const useFileUpload = () => {
|
||||
console.error('Error deleting file:', deleteResult.error);
|
||||
throw new Error(deleteResult.error || `Failed to delete ${prevPath}`);
|
||||
} else console.log('Delete sucessful!')
|
||||
console.log('Deleted file path: ', deleteResult.data)
|
||||
const updateResult = await replaceFile({
|
||||
bucket,
|
||||
prevPath: prevPath,
|
||||
file,
|
||||
options: {
|
||||
contentType: file.type,
|
||||
},
|
||||
});
|
||||
if (!updateResult.success) {
|
||||
console.error('Error updating file:', updateResult.error);
|
||||
} else {
|
||||
console.log('We used the new update function hopefully it worked!');
|
||||
return { success: true, path: updateResult.data };
|
||||
}
|
||||
}
|
||||
|
||||
let fileToUpload = file;
|
||||
|
Reference in New Issue
Block a user