For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Dashboard
GuidesIntegrationsAPI ReferencesRelease notes
GuidesIntegrationsAPI ReferencesRelease notes
  • Introduction
    • Overview
    • Quick Start
    • Projects
    • Billing
  • Uploading
    • Overview
      • Overview
      • Options
      • File validation
      • Image editor
      • Security settings
    • Uploading files with API
    • File analysis on upload
  • Optimization
    • Overview
  • Transformations
  • Delivery
    • Overview
    • On-the-fly operations
    • CDN settings
    • Proxy
  • Security
    • Overview
    • Validation and moderation
    • Signed uploads
    • Signed URLs
    • Unsafe content moderation
    • Malware protection
    • HIPAA workflows
  • Storage
    • Uploadcare storage
    • Cloudflare R2
    • Google Cloud Storage
    • Azure Blob Storage
  • File management
    • Overview
    • Managing files
    • File groups
    • Webhooks
    • Arbitrary file metadata
  • CLI
    • Overview
    • Configuration
  • Migration
    • Migration to Uploadcare
    • Migration from Filestack
Dashboard
LogoLogo
On this page
  • Simple File Size Check
  • Wrapping Validators in Functions
  • Validation Based on Data Attributes of Input Elements
  • Common Validators
  • File Size
  • File Type
  • Image Dimensions
  • Image Orientation
  • Validators as uploading widget options
UploadingjQuery Uploader

Content validation for jQuery File Uploader

Was this page helpful?
Previous

Image editor for jQuery File Uploader

Next
Built with
jQuery File Uploader package is officially deprecated as of September 1, 2025.
Moving forward, we will no longer release updates or new versions of this widget.
Support will also be discontinued, except in cases where critical security vulnerabilities need to be addressed.

We recommend considering our web-component-based File Uploader.

Content validation is a common case. You want to allow users to only upload files of certain sizes, types, image dimensions, etc. That’s where File Validation comes in. It’s carried out via validators.

Validator is a JavaScript function that receives a fileInfo object for each uploaded file and throws an exception if that file does not meet validation requirements.

Simple File Size Check

The simplest validator, which checks file sizes, can look like this:

1widget.validators.push(function(fileInfo) {
2 if (fileInfo.size !== null && fileInfo.size > 1024 * 1024) {
3 throw new Error("fileMaximumSize");
4 }
5});

Wrapping Validators in Functions

It is better to wrap validators in a function that receives a constant, like a file size threshold. Such validators can then be reused by different uploading widgets:

1function maxFileSize(size) {
2 return function(fileInfo) {
3 if (fileInfo.size !== null && fileInfo.size > size) {
4 throw new Error("fileMaximumSize");
5 }
6 };
7}
8// limit file size to 1 MB
9widget1.validators.push(maxFileSize(1024 * 1024));
10// limit file size to 2 MB
11widget2.validators.push(maxFileSize(2 * 1024 * 1024));

Validation Based on Data Attributes of Input Elements

Validation can also be implemented based on data attributes of input elements. For example, if your uploading widget has the data-max-size option enabled, we can add the maxFileSize validator in the following manner:

1$(function() {
2 $('[role=uploadcare-uploader][data-max-size]').each(function() {
3 var widget = uploadcare.Widget(this);
4 widget.validators.push(maxFileSize($(this).data('maxSize')));
5 });
6});

Common Validators

Here are some common validation cases for you to consider,

  • Limit File Size
  • Restrict File Type
  • Image Dimensions
  • Image Orientation

File Size

The example below shows how to add validation for both min and max file sizes. A validator is automatically added to each uploading widget with data-min-size and data-max-size custom attributes.

File Type

fileTypeLimit is another validator that can be added to uploading widgets with the data-file-types custom attribute whose value is a space-separated list of allowed files extensions. data-file-types can be combined with the data-input-accept-types attribute that holds accepted MIME types: audio/mpeg in the example below.

Image Dimensions

For images, you can define the maxDimensions validator that will be added to uploading widgets with either data-max-width or data-max-height custom attributes. Please note, maxDimensions only checks image dimensions even though it accepts any file type. You can combine it with the data-images-only attribute to change this behavior.

Image Orientation

This validator denies landscape images with the data-portrait-only="true" attribute and portrait images with the data-landscape-only="true" attribute. There is no point in adding both of those attributes to the same uploading widget.

Validators as uploading widget options

You can also moderate content via Uploading Widget options. Such options are called jQuery validators. Here are the most common ones:

  • Allow images only.
  • Allow certain input accept types.
  • Set uploading widget preferred MIME types.