I am trying to do something very basic, just uploading images to my storage but they are empty
This is how I upload it to Supabase
async function uploadImage(file) {
log(file)
const fileExt = file[0].filename.split('.').pop();
const fileName = `${Date.now()}.${fileExt}`;
const { data, error } = await supabase
.storage
.from('images') // Nombre del bucket
.upload(fileName, file[0]);
if (error) {
console.error('Error uploading image:', error);
return null;
}
const { publicURL, error: urlError } = supabase
.storage
.from('images')
.getPublicUrl(fileName);
console.log(publicURL)
console.log("###")
if (urlError) {
console.error('Error getting public URL:', urlError);
return null;
}
return publicURL;
}
This is where I am executing this:
app.post('/api/posts', upload.fields([{ name: 'image', maxCount: 1 }, { name: 'video', maxCount: 1 }]), async (req, res) => {
try {
const { title, content } = req.body;
// log(req.image)
// log(req.content)
let image = null;
let video = null;
if (req.files['image']) {
// image = `/uploads/${req.files['image'][0].filename}`;
const publicImageUrl = await uploadImage(req.files['image']);
image = publicImageUrl; // Use the public URL
log('Image URL obtained:', publicImageUrl);
log(`Imagen subida: ${image}`);
}
What am I doing wrong? Thank you