<script src="https:/
<script>
const picker = filestack.init('YOUR_API_KEY').picker();
document.getElementById('upload').onclick = () => picker.open();
</script>
HTML File Upload at a Glance
HTML file upload uses an <input type="file"> element inside a form that posts with enctype="multipart/form-data" to a server that stores the file. The browser handles file selection, and the server handles storage, validation and security. Filestack File Picker adds drag and drop, cloud sources, resumable uploads and managed storage to any HTML page with two lines of JavaScript.
Native HTML form
- input type="file" The user picks a file
- Your endpoint Receives the POST
- Your storage Keeps the file
Filestack File Picker
- File Picker Device, camera or cloud
- Filestack Uploads and stores it
- File URL Saved with your form
- Install
- One script tag,
filestack-js/4.x.x/filestack.min.js, ornpm install filestack-js - Works in
- Any HTML page, static or server-rendered
- Selection
- Drag and drop, paste, multiple files and folders
- Sources
- Local device, camera, URL, Google Drive, Dropbox, OneDrive, Box and more
- Storage
- Filestack storage, or your own Amazon S3, Google Cloud Storage or Azure container
- File size
- Limits depend on plan. See pricing
- Getting started
- Free plan with an API key. Compare plans
- Security
- Signed policies, domain allow-lists, and virus detection on paid plans
How HTML File Upload Works
HTML file upload takes three parts: an <input type="file"> to choose files, a form that posts them as multipart/form-data, and a server that stores them. For image upload, add accept="image/*"; for multiple files, add multiple.
<input type="file">renders the browser's file chooser, the HTML upload button.nameis the field your server reads, andacceptfilters the chooser by type.The HTML file input guide covers every attribute in depth.
A file travels in a POST request.
enctype="multipart/form-data"tells the browser to send the file's bytes along with the other fields; the default encoding sends the file name alone.Add
multipleto the input type file element for a multiple file upload in HTML. With HTML5 file upload, the selected files arrive as aFileListyou can read in JavaScript before the form submits.
<input type="file" id="avatar" name="avatar" accept="image/png, image/jpeg">
<label for="document">Document</label>
<input type="file" id="document" name="document" required>
<button type="submit">Upload</button>
</form>
<script>
document.getElementById('photos').addEventListener('change', (event) => {
for (const file of event.target.files) {
console.log(file.name, file.size, file.type);
}
});
</script>
Attribute Reference
| Attribute | What it does | Example |
|---|---|---|
accept |
Filters the file chooser by MIME type or extension | accept="image/*,.pdf" |
multiple |
Lets the user select more than one file | multiple |
capture |
Opens the device camera on mobile, front or back | capture="environment" |
required |
Blocks form submission until a file is chosen | required |
webkitdirectory |
Selects a whole folder and its files | webkitdirectory |
Accessible HTML File Upload
An accessible HTML file upload starts from the native input, which keyboards and screen readers already reach, and adds four details. The HTML file upload accessibility guide covers the full WCAG checklist.
-
A visible label
Tie a
to every file input, and name the accepted types and size in it. -
A visible focus ring
Keep the keyboard focus outline on the input or on its custom button.
-
Announced status
Write errors and upload progress into an
aria-liveregion so screen readers hear them. -
A custom button that stays reachable
Visually hide the native input with a clip pattern, so keyboards and assistive technology still reach it.
<input type="file" id="resume" name="resume" accept=".pdf"
aria-describedby="resume-status">
<p id="resume-status" aria-live="polite"></p>
What HTML File Upload Needs in Production
A production HTML file upload needs a server to store files, resume for large files, cloud imports, an accessible button, and protection against file upload vulnerabilities: type checks by content, size limits, malware scanning and signed access.
Build It on Your Server
Add Filestack File Picker
<script>
filestack.init('YOUR_API_KEY').picker().open();
</script>
Signed uploads use one small signing endpoint. Virus detection and adaptive resume run on paid plans.
Add Filestack File Picker to Your HTML Form in Two Lines
To add a file upload to an HTML form with hosted storage, load filestack-js, open File Picker from a button, and save the returned URL in a hidden field. The same picker connects Google Drive, Dropbox and other cloud sources through fromSources.
Load filestack-js from the Filestack CDN. The
4.x.xpath always serves the latest version 4 release.Initialize the client with your API key and open the picker on click.
accept,maxFiles,maxSize,fromSourcesandstoreToset what users can upload and where it lands.Write the returned URL into a hidden field. The form posts as before, and your server stores a URL instead of receiving the bytes.
Signed uploads add one small endpoint that signs a policy, or a domain allow-list limits uploads to your site.
Try the form in the live demo
<script>
const client = filestack.init('YOUR_API_KEY');
const picker = client.picker({
accept: 'image/*',
maxFiles: 1,
maxSize: 10 * 1024 * 1024,
fromSources: ['local_file_system', 'webcam', 'googledrive', 'dropbox'],
onUploadDone: saveUrl,
});
document.getElementById('pick').addEventListener('click', () => picker.open());
</script>
<input type="text" name="name" placeholder="Full name">
<input type="hidden" name="avatar_url" id="avatar_url">
<button type="submit">Save</button>
</form>
<script>
function saveUrl(result) {
document.getElementById('avatar_url').value = result.filesUploaded[0].url;
}
</script>
Features Developers Get on Top of HTML
For drag and drop file upload in HTML, Filestack File Picker lets users drop or paste images, pick files from cloud drives, and crop before upload, all from one script tag.
Drag and drop and paste
Drop files onto the picker, or paste a screenshot straight from the clipboard.
Multi-file and folder upload
Set maxFiles for several files at once, and select whole folders in File Picker 4.0.
Cloud sources and camera
Import from Google Drive, Dropbox, OneDrive, Box, a URL or the device camera.
In-browser image editing
Crop, rotate and circle-crop images before they upload.
Resumable uploads
Large files upload in chunks and resume. Adaptive Intelligent Ingestion runs on paid plans.
Security
Signed policies and domain allow-lists control uploads. Virus detection runs on paid plans.
Native HTML Input vs Filestack File Picker
A good file upload experience shows progress, previews images, accepts drag and drop and cloud files, and recovers from dropped connections. Here is how the native input and File Picker compare. Read the full comparison.
| Native HTML file input | Filestack File Picker | |
|---|---|---|
| Server-side code | An upload endpoint, storage and validation you build and run | Hosted upload and storage, plus one signing endpoint for signed uploads |
| Resumable uploads | One request per submit; a retry resends the whole file | Chunked multipart uploads that resume |
| Max file size | Set by your server configuration | Set by your plan |
| Cloud sources | Local files, plus the camera on mobile with capture |
Google Drive, Dropbox, OneDrive, Box, URL, camera and more |
| Image editing | A separate library or custom canvas code | Crop, rotate and circle before upload |
| Virus scanning | Your own scanning service | Virus detection in Workflows, on paid plans |
| Accessibility and styling | Browser-default button, restyled with a label and CSS | Prebuilt picker interface, styled through the CSS reference |
| Time to production | Depends on the backend you build | Most teams ship their first upload in under a day |
Native HTML is free and suits small internal forms backed by a server you already run.
What Happens After Upload
To generate image thumbnails automatically after upload, add a resize task to the file’s CDN URL. Every Filestack upload returns a handle and a URL that takes processing tasks.
Every upload returns a handle and a URL
- handle
- AFrHW1QRsWxmu5ZLU2qg
- url
- https://cdn.filestackcontent.com/AFrHW1QRsWxmu5ZLU2qg
Sample values from one upload.
-
Thumbnails from the URL
A resize task in the CDN URL returns a 200 by 200 crop.
https:// cdn.filestackcontent.com/ resize=width:200,height:200,fit:crop/ HANDLE -
Convert and compress
Add
output=format:webporcompressto the same URL. Image transformations -
Workflows on upload
Run virus scanning, OCR and tagging with Workflows as each file arrives, on paid plans.
-
A webhook when done
Your server receives a signed webhook when processing finishes, on paid plans.
Give your HTML form drag and drop, cloud sources and resumable uploads today.
- Most teams ship their first upload in under a day
- Trusted by 100,000+ applications
- SOC 2 compliant
HTML File Upload FAQs
How do I add a file upload to a webpage in HTML?
Add <input type="file" name="file"> inside a form with method="post" and enctype="multipart/form-data", and point the form at a server endpoint that stores the file. For hosted storage, add Filestack File Picker with one script tag.
How do I make an HTML form send the file contents?
Set enctype="multipart/form-data" and method="post" on the form. That encoding sends the file’s bytes with the other fields. The default encoding sends the file name alone.
How do I allow multiple file uploads in HTML?
Add the multiple attribute to the file input. The browser then lets users select several files, and JavaScript reads them from the input’s files list. With File Picker, set maxFiles.
How do I style the "Choose File" button?
Style a <label> tied to the input as your button, and visually hide the input with a clip pattern so keyboards and screen readers still reach it. File Picker ships its own styled interface.
Is there a file size limit for HTML file uploads?
HTML leaves file size open. The limit comes from your server configuration, or from your Filestack plan when File Picker handles the upload. See plan limits.
How can a static site accept file uploads?
Use a hosted uploader such as Filestack File Picker. Files go from the browser to Filestack storage, and a domain allow-list limits uploads to your site. Signed uploads use one small signing endpoint.