danielm / uploader

A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
https://danielmg.org/demo/java-script/uploader
MIT License
1.17k stars 385 forks source link
ajax dnd drag drop file forms javascript jquery jquery-plugin lightweight multiple progress queue upload widget

jQuery Ajax File Uploader Widget

A jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.

Very configurable and easy to adapt to any Frontend design, and very easy to work along side any backend logic.

The focus will be modern browsers, but also providing a method to know when the plugin is not supported. The idea is to keep it simple and lightweight.

Basic Javascript knowledge is necessary to setup this plugin: how to set settings, callback events, etc.

Build Status npm version Bower version

Live DEMOS

Check the live Demos here: https://danielmg.org/demo/java-script/uploader

Table of contents

Installation

NPM

npm install dm-file-uploader --save

Bower

bower install dm-file-uploader --save

Download tarball

You can download the latest release tarball directly from releases

Git

git clone https://github.com/danielm/uploader.git

Migration from v0.x.x

1.x.x got a lot of changes and new features, if you are a previous version user read CHANGELOG.md, there you can find the specific details of what was changed or removed.

Usage

As shown in the demos there are many ways to use the plugin, but the basic concepts are:

Example Markup

This is the simple html markup. The file input is optional but it provides an alternative way to select files for the user(check the online demo to se how to hide/style it)

<div id="drop-area">
  <h3>Drag and Drop Files Here<h3/>
  <input type="file" title="Click to add Files">
</div>

Initialization

   <script src="https://github.com/danielm/uploader/raw/master/path/to/jquery.dm-uploader.min.js"></script>
$("#drop-area").dmUploader({
  url: '/path/to/backend/upload.asp',
  //... More settings here...

  onInit: function(){
    console.log('Callback: Plugin initialized');
  }

  // ... More callbacks
});

Down below there is a detailed list of all available Options and Callbacks.

Additionally, after initialization you can use any of the available Methods to interact with the plugin.

Options

Callbacks

General purpose

File callbacks

All these include id

id (string): Unique ID. Useful to identify the same file in subsequent callbacks.

Validation callbacks

Methods

There are a few methods you can use to interact with the widget, some of their behavior may depend on settings.