Next.js Discord

Discord Forum

Upload file not working on vercel?

Unanswered
Barbary Lion posted this in #help-forum
Open in Discord
Barbary LionOP
I am trying to upload an image it works fine locally but when in production on vercel it suddenly pop an error and it says FormData is null.

4 Replies

Barbary LionOP
form submit is here

onSubmit={async (values, { resetForm }) => {
            setClear(false)

                const formData = new FormData();
                formData.append('file', values.files);
                formData.append('title', values.title);
                formData.append('description', values.description);
            
                try {
                    setLoading(true)
                    const res =  await axios.post('/api/va/certificate/upload', formData, {
                            headers: {
                            'Content-Type': 'multipart/form-data',
                            },
                        });
                    if(res.status === 200){
                        props.handleFetch();
                        setLoading(false)
                        setClear(true)
                        resetForm();
                        Swal.fire('Add Certificate', 'Certificate Uploaded', 'success');

                    }
                } catch (error:any) {
                     console.log(error)
                     Swal.fire('Something went wrong', JSON.stringify(error), 'error');

                }

        }}
or use signed url of AWS or GCP to store files if u use one.
caveat. the content is not for Page Router but App Router.