SupabaseS
Supabase4y ago
ven

Not able to upload avatar to storage bucket using formidable

I am building an app in Nuxt 3 and trying to upload an avatar to the storage bucket through an api call to my server. i parse the files using formidable like so
    const form = formidable({ multiples: true });
    const client = await serverSupabaseClient(event);

    const response = await new Promise((resolve, reject) => {
        form.parse(event.req, (err, fields, files) => {
            if (err) {
                reject(err);
            }
            resolve({ fields, files });
        });
    });
    const { fields, files } = response;
and then i rename my file removing any blank spaces
    const fileName = encodeURIComponent(
        files.avatar.originalFilename.replace(/\s/g, '-')
    );
and try to upload the file
    // upload the file to supabase storage
    const { data, error } = await client.storage
        .from('site')
        .upload('public/' + Date.now() + '-' + fileName, files.avatar);
    return data;
i get no error and there is no file in storage. any thoughts on what could be happening?
Was this page helpful?