Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To let a visitor choose an image and send it to your site, add a named <input type="file"> to a form that uses method="post" and enctype="multipart/form-data". The form sends the file to an upload handler on your server; HTML provides the selection and submission controls, but it does not store or process the image by itself.

Make a basic image upload form

Use a real upload-handler URL in the form’s action. The example uses /upload as a route name; it will work only if your site has a server endpoint configured to receive and process uploads at that path.

<form action="/upload" method="post" enctype="multipart/form-data">
  <label for="image">Choose an image:</label>
  <input id="image" name="image" type="file" accept="image/*" required>
  <button type="submit">Upload</button>
</form>

Each part has a specific job:

  • type="file" opens the visitor’s file picker. After selection, the browser can submit the file with the form or expose it to JavaScript through its file APIs.
  • name="image" identifies the field in the submitted request. The server uses this field name when reading the uploaded file. An id is useful for connecting the input to its <label>, but it does not replace name.
  • method="post" submits the form as a POST request rather than placing the file in the page URL.
  • enctype="multipart/form-data" tells the browser to encode the request as form data that can include a file. Without it, the form does not submit the file in the required multipart format.
  • action="/upload" names the destination handler. Change it to the route your application actually implements.

required makes the browser require a selection before the visitor submits the form. It improves the form interaction, but the server still needs to handle requests directly and enforce its own rules.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose whether to restrict the file picker

The accept attribute can guide the picker toward suitable files. For an image field, accept="image/*" allows the picker to show image formats broadly. If the application supports only particular formats, use an explicit list instead:

#1 Best Overall
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty
<input id="image" name="image" type="file"
       accept="image/png,image/jpeg" required>

This example guides the visitor toward PNG and JPEG files. The exact list should match the formats your application intends to accept. The accept value is a picker hint, not a security check or proof that a selected file is valid. A visitor or a crafted request can bypass client-side guidance, so the receiving server must validate the uploaded content and enforce its own accepted formats and request-size limits.

Choose a normal form or an asynchronous upload

Both approaches send a file to a server as multipart form data. A regular form is the simplest choice when it is acceptable for submission to navigate to a response page or reload the current page. JavaScript is useful when the interface should stay on the page, show a status message, or add custom interaction. JavaScript changes how the browser submits the request; it does not eliminate the upload endpoint or server-side processing requirement.

Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]
Approach Good fit What the server receives
HTML form submission A straightforward upload where navigation or a page response is acceptable. A POST request encoded as multipart/form-data.
JavaScript with fetch and FormData An interface that needs dynamic feedback or should not navigate away on submission. The same kind of multipart form data; the server endpoint still needs to accept it.

Send the selected file with JavaScript

This complete browser-side example uses the same form fields, prevents the usual form navigation, sends the selected file to the form’s action, and displays a basic success or error message based on the HTTP response. It assumes that /upload is a server route that accepts this multipart request and returns an appropriate HTTP status.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
<form id="image-form" action="/upload" method="post"
      enctype="multipart/form-data">
  <label for="image">Choose an image:</label>
  <input id="image" name="image" type="file"
         accept="image/*" required>
  <button type="submit">Upload</button>
  <p id="upload-status" role="status"></p>
</form>

<script>
  const form = document.querySelector('#image-form');
  const status = document.querySelector('#upload-status');

  form.addEventListener('submit', async (event) => {
    event.preventDefault();
    status.textContent = 'Uploading…';

    try {
      const response = await fetch(form.action, {
        method: 'POST',
        body: new FormData(form)
      });

      if (!response.ok) {
        throw new Error(`Upload failed (HTTP ${response.status})`);
      }

      status.textContent = 'Upload complete.';
    } catch (error) {
      status.textContent = error.message || 'Upload failed.';
    }
  });
</script>

new FormData(form) gathers the named fields, including the selected file. The browser must set the request’s Content-Type header and include the multipart boundary that separates parts of the request. Do not manually set Content-Type: multipart/form-data when sending a FormData body: doing so can omit the boundary value the server needs to parse it.

Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers

The example treats any successful HTTP status as completion; it does not display a server-provided file URL or other response data. If your endpoint returns structured data, extend the success branch to read that response in the format your server sends. Make sure the endpoint’s response contract is clear to both the browser code and the server implementation.

What the upload handler must do

The form and JavaScript examples are only the browser side of an upload. The receiving route needs to understand the submitted multipart request, retrieve the file under the submitted field name (here, image), and decide what to do with it. That might include saving it or passing it to another part of the application; the HTML itself does neither.

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.

Before accepting an upload, the server should validate the content and enforce its own size and request limits. Do not rely on accept, required, the file’s displayed name, or browser-side checks as a substitute for server-side rules. A configured request-size limit can also affect the outcome: if an upload exceeds the server’s limit, the handler may not receive it as a normal successful submission. The limit and exact failure response depend on your server configuration, so check the application and hosting settings that govern request size.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Define which formats the application accepts, then validate uploaded content against that policy on the server.
  • Set a request-size limit that suits the application and handle rejected or oversized requests with a useful response.
  • Return a meaningful HTTP result so the browser interface can distinguish a successful upload from a failed one.
  • Keep the HTML field name and the name expected by the server in sync.

Troubleshoot common upload failures

Symptom Likely cause What to check
The server receives no file. The file input has no name, the form does not use multipart/form-data, or JavaScript is not including the form data. Confirm the input is named, the form has the multipart encoding, and the submitted field name matches what the handler reads.
Submitting the form reaches a not-found page. The action route is missing or points to the wrong handler. Use the actual upload route implemented by your application; /upload is only an example path.
The picker offers the wrong kinds of files. The accept hint is too broad, too narrow, or omitted. Set it to image/* for a broad image hint or list the intended MIME types, such as image/png,image/jpeg.
The server rejects a file the picker allowed. The picker hint does not validate content, or the server’s policy differs from the picker’s guidance. Align the server’s accepted-format rules with the interface, while keeping server-side validation authoritative.
The upload works for small files but fails for larger ones. A server or hosting request-size limit may be rejecting the request. Check configured upload and request limits, then show the visitor a clear rejection message where possible.
The JavaScript request fails or the status stays at “Uploading…”. The endpoint may be unreachable, may return an error, or may not accept the multipart body. Check the browser’s network and console panels, verify the route and server response, and confirm that the handler parses multipart form data.
The JavaScript multipart request is not parsed correctly. The code may have set its own multipart Content-Type header without the boundary. Remove the manually set header and let the browser create it when sending FormData.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability considerations

For a basic upload, begin with the normal form unless the page needs an asynchronous interaction. It uses fewer moving parts in the browser, while the asynchronous version gives the page control over feedback and navigation. Neither approach changes the fact that file transfer and processing depend on the receiving server and its configured request limits.

Best Value
Sale
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

For larger files, consider what the visitor sees while the request is in progress and how the endpoint reports rejection or failure. The small fetch example above provides a pending message and a success or error result, but it does not implement a progress indicator, retry behavior, or resumable transfer. Those requirements need additional client and server design rather than a different HTML attribute.

Keep validation and limits on the server even if the page provides a polished picker or checks a selection before sending it. Browser-side behavior is there to guide the visitor; it cannot replace the endpoint’s decision about whether to accept a request.

Or skip the browser setup

If by “upload an image” you mean obtaining a screenshot of a webpage rather than letting a visitor submit an image file, ScreenshotNeo is a different tool: a website screenshot API and MCP server. It does not receive the visitor’s chosen image or replace an application’s upload handler. For webpage captures, it can return an image or PDF from a single request. See the ScreenshotNeo API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

With ScreenshotNeo, cookie banners are accepted and removed before the capture, along with supported newsletter popups and chat widgets; those cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server offers screenshot tools for Claude, Cursor and other MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for the free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.