© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
ven

uploading file to storage convert file to garbage

I am trying to upload a file using server side API in Nuxt and the formidable package. For some reason the file is converting to garbage on supabase
here is my code
    const {fields, files} = response;
    const avatar = files.avatar;
    // creates a valid name by removing spaces
    const fileName = encodeURIComponent(
        avatar.originalFilename.replace(/\s/g, "-")
    );
    // renames the file in the directory
    fs.renameSync(avatar.filepath, fileName);    
    console.log(avatar)
    const avatarData = fs.readFileSync(fileName)
    const {data, error} = await client.storage
        .from("site")
        .upload("public/" + Date.now() + "-" + fileName, avatarData, {
            cacheControl: "3600",
            upsert: false,
        });
    const {fields, files} = response;
    const avatar = files.avatar;
    // creates a valid name by removing spaces
    const fileName = encodeURIComponent(
        avatar.originalFilename.replace(/\s/g, "-")
    );
    // renames the file in the directory
    fs.renameSync(avatar.filepath, fileName);    
    console.log(avatar)
    const avatarData = fs.readFileSync(fileName)
    const {data, error} = await client.storage
        .from("site")
        .upload("public/" + Date.now() + "-" + fileName, avatarData, {
            cacheControl: "3600",
            upsert: false,
        });
Screen_Shot_2022-10-14_at_7.04.46_AM.png
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

error when uploading a file to storage
SupabaseSSupabase / help-and-questions
13mo ago
Issue in uploading file to S3 bucket or storage
SupabaseSSupabase / help-and-questions
14mo ago
Error when uploading to Storage (Swift)
SupabaseSSupabase / help-and-questions
4y ago
Error while uploading image to storage bucket
SupabaseSSupabase / help-and-questions
6mo ago