Uploadcare jQuery File Uploader
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:
Features
jQuery File Uploader helps you perform the following tasks:
- Uploading
- Add a file uploading capability to your website or app.
- Upload files of any type and up to 5 TB in size.
- Get files from various upload sources, including local storage, camera, social media, and cloud storage services.
- Upload multiple files in one go.
- Track upload jobs with an individual progress bar for each file.
- Speed up the uploading with the uploading network (it works like CDN).
- Image Handling
- Show image previews.
- Implement custom image crop options.
- Edit, enhance, and apply photo filters to images in any browser.
- Validation
- Validate files by their format or size.
- Validate files by their MIME type (server-side filtering).
- Automatically resize large incoming images.
- Security
- Make your uploading system compatible with SOC 2, HIPAA, and more.
- Prevent remote code execution through File Uploading.
- Prevent code execution in uploaded files like
SVG
,html
andxml
.
- Reliability
- All your uploads go to the storage covered by SLA with a 99.9% uptime.
Supported browsers
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.
Installation
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.
Dependencies
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:
Bundles
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.
Global installation
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:
NPM
You can get the widget instance and configure it with configuration object:
Configure
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:
- Global variables, initialized on page load.
- Local attributes, initialized when a new widget instance is created.
- The
settings
object.
Global variables
Globals are specified as global JavaScript variables in your <script>
tag.
For example:
Local attributes
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:
Settings object
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:
Upload sources
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.
List of supported upload sources
Configuring upload sources
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:
Custom tabs
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.
Registering a new tab
Register a new tab via the registerTab
method.
Coding tab’s actions
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
.
Adjusting the look
Customize your custom tab’s look via CSS. Use <svg>
and <symbol>
elements:
Custom tab in action
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:
Multiple file uploading
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 uploading
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.
Automatically resize uploaded images
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:
- Users don’t need to downscale images on their devices to meet the uploading requirements.
- Optimized storage.
- Faster uploading.
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%.
Specs and limits
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:
- When a client browser doesn’t support a specified output resolution.
- For images uploaded from social media and URLs.
- If the
original resolution
is less than 2x larger than thetarget 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. - If the image color mode is CMYK.
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.
Resize to 1 MP on a client side:
Resize multiple files to 0.4 MP on a client side:
Localization
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.
There currently are:
You can either set an existing locale or add a custom one along with its pluralization rules.
Adding a locale
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
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:
Styling
jQuery File Uploader can be easily integrated into your product and match your website look or a web app’s UI.
Styling With CSS
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 uploader button color
Changing the button color is one of the most common cases:
Button shadow
You can add shadow and experiment with fonts and colors:
Uploading circle color
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:
Custom progress bar
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.
Uploaded image preview
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.
jQuery File Uploader embed
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.
Embed jQuery File Uploader using panel
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.
Panel styling
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.
Image crop
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.
How cropping works
Technically, image cropping works as post-processing via the Image processing feature:
- Original images go to an Uploadcare project associated with a Public Key set as your widget instance.
- The crop is applied as the
crop
image processing operation by injecting its URL directive into original URLs. - The widget returns resulting CDN URLs with an injected
crop
.
Configuring 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.
Default files in the widget dialog
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 or
UUID.
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:
JS snippets and CSS tricks
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!
Paste an image from the clipboard
Get a CDN URL of an uploaded file
For a single-upload widget.
Get CDN URLs of uploaded files
For a multi-upload widget.
Get a group CDN URL
For a multi-upload widget.
Get a CDN URL of an uploaded file/group
For a dialog window.
Get a camera-recorded video duration
Check if a file was added or removed
Get the upload source
Add an overlay to the crop
Get a selected crop preset
Upload an image from Base64
Render the uploaded image preview
Add custom names to crop presets
Add custom widget button labels
Reset the widget after upload
Add a custom message to the dialog
Video record time limit
Versioning
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.