Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
Why file upload doesn't work in formsubmit.co when using AJAX form method?

I have a static website built with Gatsby and there is a contact form including file upload. Cause I don't want to setup a back-end, I choose FormSubmit.co service to handle sending email on every form submissions.

It worked fine uploading file and I received the file in my email just when I used the method: adding the endpoint to the form action action="https://formsubmit.co/my@email.com", As described in DOCS .
But that method redirects page to another; so because I don't want the page to be redirected and wanna show my own message, I decided to use the AJAX method.

This is my code getting Name and File from user, and the handleSubmit function:

import React, { useRef } from 'react';

const MyForm = () => {
 const form = useRef(null);

 const handleSubmit = (e) => {
    e.preventDefault();
    const data = new FormData(form.current);

    fetch('https://formsubmit.co/ajax/my@email.com', {
      method: 'POST',
      body: data,
    })
      .then((response) => response.json())
      .then((data) => console.log(data))
      .catch((error) => console.log(error));
  };

 return (
  <form ref={form} method="POST" encType="multipart/form-data" onSubmit={handleSubmit}>
    <input id="name" name="Name" />
    <input type="file" id="file" name="File" />
    <button type="submit">Send</button>
  </form>
 );
};

The problem is while using AJAX form, the file wouldn't upload and I don't receive it in my email. But there is no error msg and even I think the file has been sent! according to the POST request at network:

File data in nework POST request
I've also tried Axios library, but it didn't work either.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

maybe > encType="multipart/form-data" should be remplaced by another parameter?

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda