jquery-image-uploader
jquery-image-uploader is a jquery plugin to upload file.
It supports drag&drop and file API.
The plugin has a automatic "fallback" mode.
This plugin is not really production-ready.
Installation
bower install --save jquery-image-uploader
Or copy the dist/jquery.uploader.min.js
file on your server.
Usage
Basic usage
$('#dropZone').imageUploader({
fileField: '#files',
urlField: '#url',
url: 'ajaxUpload.php',
afterUpload: function (data) {
console.log(data);
},
error: function(msg) {
alert(msg);
}
});
If you drag and drop an image on the "dropZone" or if you use the classic file button, it will call the url, with the file as an argument.
If you specify a url in the "urlField" field, it will call the url with a POST['url'] attribute containing the image url.
Possible options (with default values)
$('#dropZone').imageUploader({
fileField: null,
urlField: null,
urlFieldSubmit: null,
hideFileField: true,
hideUrlField: true,
url: 'ajaxUpload.php',
thumbnails: {
div: null,
width: null,
height: null,
crop: null
},
maxFileSize: 0,
allowDuplicate: false,
onFilesSelected: function() { return false; },
onDragLeave: function(event) { return false; },
onDragEnter: function(event) { return false; },
onDragOver: function(event) { return false; },
onDrop: function(event) { return false; },
onUploadProgress: function(event) { return false; },
beforeUpload: function() { return true; },
afterUpload: function() { return false; },
error: function(msg) { alert(msg); },
thumbnailReady: $.noop
});
Advanced usage
You can access the ImageUploader object by getting the imageUploader
data attribute.
You can then interact on the object itself.
Example
var imgUrl = 'http://octodex.github.com/images/original.png';
$('#dropZone').data('imageUploader').addFileByUrl(imgUrl);