Back

ExperimentalWarning: buffer.File is an experimental feature and might change at any time

  • 0
  • Web
  • Storage
  • Cloud
Edward Alderson
28 Nov, 2024, 19:42

Dear all,

I was trying to use Server Actions in my NextJs app to upload to Storage a file uploaded from a client form. On local environment everything works just fine, but on Netlify the process stops. After three days I understood the problem sits with Netlify. In the logs I see:

ERROR: ExperimentalWarning: buffer.File is an experimental feature and might change at any time ERROR ReferenceError: File is not defined

TL;DR
Experimental feature warning on 'buffer.File' in the code related to file uploads in a Next.js app using Server Actions. Works locally but stops on Netlify due to 'File is not defined' error. This issue is related to 'buffer.File' being an experimental feature that might change at any time. Consider adjusting the code to avoid using experimental features if possible.
Edward Alderson
28 Nov, 2024, 19:42

For context, this is the code regarding the file upload in my form component

TypeScript
const onSubmit = async (values: z.infer<typeof MaestroFormValidation>)  => {
let formData = new FormData();

    if (values.fronte_documento_identita && values.fronte_documento_identita.length > 0) {
      const blobFile = new Blob([values.fronte_documento_identita[0]], {
        type: values.fronte_documento_identita[0].type,
      });

      formData.append("fronte_blobFile", blobFile );
      formData.append("fronte_fileName", values.fronte_documento_identita[0].name);
    }

    if (values.retro_documento_identita && values.retro_documento_identita.length > 0) {
      const blobFile = new Blob([values.retro_documento_identita[0]], {
        type: values.retro_documento_identita[0].type,
      });
    
      formData.append("retro_blobFile", blobFile);
      formData.append("retro_fileName", values.retro_documento_identita[0].name);
    }
Edward Alderson
28 Nov, 2024, 19:42

while this is the code that takes in the data and pushes it to storage

TypeScript

let file;
        if (fronte_documento_identita) {
            const inputFile =
            fronte_documento_identita &&
            InputFile.fromBuffer(
                fronte_documento_identita?.get("fronte_blobFile") as Blob,
                fronte_documento_identita?.get("fronte_fileName") as string
        )

            file = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile);
            if (file instanceof Error){
                throw file
            }
        }

        let retroFile;
            if (retro_documento_identita) {
                const inputFile =
                retro_documento_identita &&
                InputFile.fromBuffer(
                    retro_documento_identita?.get("retro_blobFile") as Blob,
                    retro_documento_identita?.get("retro_fileName") as string
            );

                retroFile = await storage.createFile(BUCKET_ID!, ID.unique(), inputFile);
                if (retroFile instanceof Error){
                    throw retroFile
                }
            }
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more