Advanced File Uploader
For large attachments or multiple file uploads, use our advanced file uploader.
Last updated
<form action="https://api.web3forms.com/submit" method="POST">
...
<! -- Step 1: Add this line -->
<input type="file" data-advanced="true" name="attachment" style="display:none;" />
...
</form><! -- Step 2: Add our script to load the file uploader -->
<script src="https://web3forms.com/client/script.js" async defer></script> <input type="file"
name="attachment"
data-form-id="YOUR_ACCESS_KEY_OR_FORM_ID_HERE" (required if not added in `form` )
data-advanced="true" (enable advanced file upload)
accept="image/*, application/pdf" (accept only some file types)
data-max-files="3" (Total number of files allowed)
data-max-file-size="5MB" (Maximum file size for single item)
data-content="Drag & Drop or <i>Browse<i>" (Custom Label in your language)
/><form action="https://api.web3forms.com/submit" method="POST">
<input type="hidden" name="access_key" value="YOUR_ACCESS_KEY_HERE">
<input type="text" name="name" required>
<input type="email" name="email" required>
<textarea name="message" required></textarea>
<! -- Step 1: Add this line (showing advanced options) -->
<input
type="file"
name="attachment"
data-advanced="true"
multiple
data-max-file-size="3MB"
data-max-files="3" />
<button type="submit">Submit Form</button>
</form>
<! -- Step 2: Add the script -->
<script src="https://web3forms.com/client/script.js" async defer></script><!-- Dark Theme -->
<style>
.filepond--panel-root {
background-color: #2c2c2c;
}
.filepond--drop-label {
color: #d4d4d4;
}
</style>
<script>
const form = document.getElementById('YOUR_FORM_ID');
form.addEventListener('submit', function(e) {
const fileInput = form.querySelector('[name="attachment"]').value;
if (!fileInput) {
e.preventDefault();
alert("Please upload files first!")
return
}
});
</script>const form = document.getElementById('form');
const submitBtn = form.querySelector('button[type="submit"]');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(form);
const object = Object.fromEntries(formData);
const json = JSON.stringify(object);
const originalText = submitBtn.textContent;
submitBtn.textContent = "Sending...";
submitBtn.disabled = true;
try {
const response = await fetch("https://api.web3forms.com/submit", {
method: "POST",
body: json,
headers: {
"Content-Type": "application/json"
}
});
const data = await response.json();
if (response.ok) {
alert("Success! Your message has been sent.");
form.reset();
} else {
alert("Error: " + data.message);
}
} catch (error) {
alert("Something went wrong. Please try again.");
} finally {
submitBtn.textContent = originalText;
submitBtn.disabled = false;
}
});import React, { useState } from 'react';
import { FilePond, registerPlugin } from 'react-filepond';
import 'filepond/dist/filepond.min.css';
// Register plugins if needed
// registerPlugin(FilePondPluginImageExifOrientation, FilePondPluginImagePreview);
function FileUploader() {
const [files, setFiles] = useState([]);
const getPresignedUrl = async (file) => {
try {
const response = await fetch(`https://api.web3forms.com/upload?file=${file.name}`);
const data = await response.json();
return data;
} catch (error) {
console.error('Error generating pre-signed URL:', error);
throw error;
}
};
return (
<FilePond
files={files}
onupdatefiles={setFiles}
allowMultiple={true}
maxFiles={3}
name="attachment"
labelIdle='Drag & Drop your files or <span class="filepond--label-action">Browse</span>'
server={{
process: async (fieldName, file, metadata, load, error, progress, abort, transfer, options) => {
try {
const { url, key } = await getPresignedUrl(file);
const response = await fetch(url, {
method: 'PUT',
body: file,
headers: {
'Content-Type': file.type,
},
});
if (response.ok) {
load(key);
} else {
error('Upload failed');
}
} catch (err) {
error('Error uploading file');
}
},
}}
/>
);
}
export default FileUploader;import React from 'react';
import FileUploader from './FileUploader';
function App() {
return (
<div className="App">
<h1>File Upload Example</h1>
<form method="POST" action="https://api.web3forms.com/submit">
<input
type="hidden"
name="access_key"
value="c00d70af-1ca3-466d-98a7-c82408e76e91"
/>
<input type="text" name="First Name" />
<FileUploader />
<input type="submit" value="Submit" />
</form>
</div>
);
}
export default App;import { useForm, Controller } from "react-hook-form";
import FileUploader from './FileUploader';
export default function Support() {
const { register, handleSubmit } = useForm({
mode: "onTouched",
});
const onSubmit = async (data, e) => {
// Replace with actual call to Web3Forms
console.log(data);
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<input type="text" {...register("name")} />
<Controller
control={control}
name="attachment"
render={({ field }) => (
<FileUploader
onChange={(e) => field.onChange(e.cdnUrl)}
/>
)}
/>
<button type="submit">Submit</button>
</form>
);
}