Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!