Uploadcare jQuery File Uploader is responsive and mobile-ready HTML5 widget that allows users to select and upload multiple files from various sources. Also, it includes an in-browser image editor. You can customize the appearance and functionality to match your website and task.
jQuery File Uploader is supplied as a JavaScript library. It overrides an <input type="file">
control on an HTML page with a button that opens up the uploading widget dialog.
Like this:
jQuery File Uploader helps you perform the following tasks:
SVG, html and xml.jQuery File Uploader works in all modern browsers, desktop and mobile. Here’s a list of supported browsers:
jQuery File Uploader will most probably run in older browser versions as well. More on browser version support.
Select either option to install jQuery File Uploader:
Refer to no-code integrations to use the uploading widget with your website platform like Shopify, etc.
Before proceeding with your install, check out the dependencies and jQuery File Uploader bundles below.
jQuery File Uploader doesn’t have any external dependencies except for jQuery. Generally, the uploading widget comes in two versions: with and without embedded jQuery library.
For example, you can use jQuery commands on the page if you included a bundle with jQuery:
Depending on your project, you can select a specific JS library bundle:
uploadcare.full.js — a full bundle with built-in jQuery.uploadcare.js — a default bundle without jQuery.uploadcare.api.js — a bundle without uploading widget UI and jQuery JavaScript API only.uploadcare.lang.en.js — a bundle without jQuery, en locale only.Include a minified bundle version by adding .min before .js.
By default, minified (and without jQuery) uploadcare.min.js is exported to NPM
and other package managers.
Get your public API key and
include this into the <head>:
Note: If you already use jQuery, you can use the alternative bundle that comes without jQuery, so you won’t download it twice.
Now you can use the Uploader:
You can get the widget instance and configure it with configuration object:
Set of features, such as upload sources, image editing tools, can be customized via the widget options.
You can have mixed settings for different widget instances. Global variables will affect all File Uploader instances, and local attributes will override global settings.
Here’s how you can configure jQuery File Uploader:
settings object.Globals are specified as global JavaScript variables in your <script> tag.
For example:
Local options are specified in the target <input> tag as data-* attributes.
For example:
When setting boolean options locally in HTML tag attributes, any value or no
value is considered as true:
To disable a local option, use either:
Most of the widget options can also be set within the settings object.
See the jQuery File Uploader API reference for more details.
For example:
jQuery File Uploader supports more than a dozen of upload sources, including local file storage, web camera; external URL; cloud services, and social networks. In UI, the sources are shown as tabs.
The set of enabled upload sources is controlled via the data-tabs
option.
You can configure the set of upload sources globally or per jQuery File Uploader
instance. The global parameter is called UPLOADCARE_TABS. Locally you can
utilize the data-tabs attribute.
In both cases, you’ll pass a space-separated string with tab names.
Configuring the set of sources globally:
Configuring the list of sources locally:
You can add custom tabs into your widget. These tabs can be additional upload sources or whatever you design them to be. For example, display all uploaded files.
Register a new tab via the registerTab method.
Once the tab is registered, write a custom code. The following code will display
uploaded images made with this widget instance. It’ll pass a list of file
UUIDs with the settings object. When a user
selects a file for uploading, the file info can be passed to the dialog using
dialogApi.
Customize your custom tab’s look via CSS. Use <svg> and <symbol> elements:
Here’s a live example of jQuery File Uploader with the custom tab we’ve just created. It displays images uploaded with this the uploading widget instance:
jQuery File Uploader allows you to upload multiple files in one go. Each file will have its tiny progress bar and a preview when it’s uploaded.
The uploading widget will display individual errors if some files couldn’t be uploaded (e.g., due to size or format validation failure) and it won’t affect the rest of the upload.
Enable batch file uploading with the data-multiple attribute
in the widget <input> element.
Check out multiple file uploading:
Multiple file uploads are collected as file groups with
respective group_id as opposed to single file UUIDs.
jQuery File Uploader lets you accept hi-res images and shrink them in size to a reasonable resolution, keeping the original aspect ratio.
Benefits of automatic image resize on upload:
Use the data-image-shrink option to apply
client-side image resize with values like:
800x600, shrinks images to 0.48 megapixels with the default JPEG quality of
80% (default, when not set).1600x1600 95%, shrinks images to 2.5 megapixels with the JPEG quality set to
95%.The output resolution limit for data-image-shrink is 268 MP (e.g., 16384x16384).
It conforms to the maximum resolution that WebKit desktop browsers support.
We recommend not to use values greater than 16.7 MP (4096x4096),
because it’s a current limit for iOS devices.
Uploaded images won’t be shrunk in the following cases:
original resolution is less than 2x larger than the target resolution.
For example, it won’t shrink a 2560x1560px (4 MP) image to 1600x1600px (2.5
MP). It will work if you had a 2448x3264px (8 MP) input image. This
limitation preserves an optimal image quality and file size balance.The output format will be JPEG by default unless your input image has an alpha channel (transparency). In this case, PNG will be used instead. Grayscale images will be converted to RGB.
EXIF and ICC profile info is copied as-is and includes an original image orientation, camera model, geolocation, and other settings of an original image.
jQuery File Uploader is highly customizable and implements UI localization and custom pluralization rules. With locales, you can make your app instantly adapt to user languages.
You can either set an existing locale or add a custom one along with its pluralization rules.
You can add your localization, if there’s no one yet, by forking the main jQuery File Uploader repo and adding a new localization file to this list.
Another option is overriding specific locale items in your global uploading widget configuration:
The default is an English locale. If a string item is missing in a locale you created or customized, English will be a fallback.
Uploading errors can also be redefined in the locale. You can see errors reference.
Pluralization rules may vary in different languages. In the English locale,
there’ll be "1 file", but "3 files". This rule is described under the
file: key in the locale file.
Strings with quantitative values are based on what a pluralization function returns. You’ll pass a number into a function, and it’ll output a subkey related to your input.
There are two subkeys for the English localization: one and the other.
However, it can get more complex with other languages. For example, take a look
at the file: subkeys for the Russian locale.
The %1 sequence is used to format numbers into pluralized strings.
Each locale we provide with jQuery File Uploader is supplied with its Unicode-based
pluralization rules. If you wish to override those,
you can define a custom pluralization function and assign it to the
UPLOADCARE_LOCALE_PLURALIZE variable.
The following setting makes the widget use the message under the some
subkey for input numbers from 2 to 10:
jQuery File Uploader can be easily integrated into your product and match your website look or a web app’s UI.
jQuery File Uploader is thoroughly annotated with CSS classes. It’s your starting point into deeper customization. You can find a class for every widget item by inspecting its elements or sifting through jQuery File Uploader source code.
The uploading widget dialog window look can be customized via the
uploadcare--dialog class.
Changing the button color is one of the most common cases:
You can add shadow and experiment with fonts and colors:
You can display the file uploading progress. The fill color can be changed via
the CSS color property, while border-color will work for your background.
Here, you can test the widget with a customized uploading circle:
You can replace the built-in progress bar. To do that, you need to add a
listener to the current widget instance and get it in the onChange
callback. It’ll be a file object for the regular widget or a group object
for multiple widgets. After that, listen to the progress event and
change your progress bar according to the current uploadProgress.
The following installProgressBar function does all that. It receives the two
arguments: the widget instance and a progress bar DOM element. Everything
else runs on CSS, animation included.
The default jQuery File Uploader behavior is to show an image preview when a user selects an image. You might want to embed this preview on your page somewhere around the widget button. Such a preview could be more informative than simply displaying file names and sizes.
Note, you have full control over the size and position of your embed. Just use CSS.
Image preview for a multi-file widget may look differently:
You can change the displayed images or rearrange the existing ones; all changes will then be reflected in the thumbnail list.
User experience means the world to us. Therefore, we provide a lot of customization options that cover both jQuery File Uploader appearance and behavior.
The look of jQuery File Uploader can be changed via CSS, is a great starting point for controlling your widget behavior.
Another thing you can do is to embed jQuery File Uploader as a panel as opposed to a default dialog window.
By default, the widget dialog appears on a button click. The dialog will appear in a lightbox, which overlays your page’s content and dims the background.
However, you might want to show the widget interface right away. This
appearance is named panel.
The snippet above replaces your DOM element with the uploadcare-placeholder ID
and puts it in place once a user selects a file. This can be used to indicate
the uploading process. Also, the panel can be closed by simply selecting a file.
Similar to jQuery File Uploader dialog, the panel can be customized.
The appearance of your embed can be changed via CSS. In this example, we remove a sharp border:
Some dialog elements are rendered as iframe by Uploadcare servers, which
doesn’t let you customize CSS. However, we provide a set of specific methods
to inject CSS into iframes.
Cropping images is one of the most common tasks, so we added it right in the jQuery File Uploader UI.
jQuery File Uploader features a good bunch of crop options, including free
crop. Adding the feature to your widget instance is done by implementing
the data-crop option.
Note that it’ll add an additional step of image editing.
Technically, image cropping works as post-processing via the Image processing feature:
crop image
processing operation by injecting its URL directive into original URLs.crop.Crop options are held inside the data-crop attribute as a comma-separated
string with presets names. When you define several presets, users will be able
to choose from the related crop options right in the UI.
Each crop preset is a combination of a size or ratio definition and an optional keyword:
"disabled", crop is disabled. It can’t be combined with other presets."" or "free", crop is enabled. Users can freely select any crop area on
their images."2:3", any area with the aspect ratio of 2:3 can be selected for cropping."300x200" — same as above, but if the selected area is greater than 300x200
pixels, the resulting image will be downscaled to fit the dimensions."300x200 upscale" — same as above, but even if the selected area is smaller,
the resulting image gets upscaled to fit the dimensions."300x200 minimum" — users won’t be able to define an area smaller than
300x200 pixels. If an image we apply the crop to is smaller than 300x200
pixels, it will be upscaled to fit the dimensions.jQuery File Uploader allows you to make specified files appear in jQuery File Uploader dialog on open.
Specify these files by adding the value attribute to your widget
<input> element. The attribute may either be empty or hold a file CDN URL.
If you set the value externally and trigger the DOM change event, it affects the widget.
For instance, setting it to a file UUID or a CDN URL will result in that the file being loaded into jQuery File Uploader.
You can apply it anytime, and it’ll take effect immediately.
Here’s how you do it:
After uploading, the uploading widget loads image previews from the CDN:
With this feature turned on, the uploading widget can’t show previews because signed URLs include a token part. To work that around, you can load images through a proxy backend, where it can hook up the token info:
Here are two options that can help you show image previews:
previewProxy. It proxies the data
related to image previews.previewUrlCallback. It works if
you need to send extra data like JWT tokens.previewProxyImplementing the previewProxy option works best for these cases:
To use previewProxy option, specify your proxy backend endpoint URL, and
you’re good to go:
It’ll let the uploading widget load image previews via the following URL:
It appends a query parameter with image preview URL to previewProxy:
By default, the uploader uses url as the query parameter name, but you
can have a custom naming as well:
previewUrlCallbackThis option provides you with explicit control over the uploading widget preview
URLs. In code, previewUrlCallback is a function with a signature:
Example:
Note, previewUrlCallback overrides previewProxy, and the latter option will
be ignored.
In this cookbook part, you can find popular code examples and resolutions of common tasks when working with jQuery File Uploader. Less words, more code!
For a single-upload widget.
For a multi-upload widget.
For a multi-upload widget.
For a dialog window.
When we introduce backward-incompatible changes, we release new major versions. Once published, such versions are supported for 2 years. You will still be able to use any file uploader version after its support term at your own risk.