• Stars
    star
    121
  • Rank 287,958 (Top 6 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created about 8 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“Ž AngularJS directive for Dropzone, an easy to use drag'n'drop file upload library.

Need maintainers

This project is no longer maintained. Though this project is in good health, we would appreciate if someone collaborates to fix potential bugs and enhancement requests.


ng-dropzone bower npm downloads preview

AngularJS directive for dropzone

UPDATE

In latest release v1.0.5, distribution files have been renamed to match newly changed package name. Please rename urls to distribution files if you are updating this package. Also, gulp and sass support have been added.


1. Getting started

β†’ Install using npm

npm install ngdropzone

β†’ Install using bower

Run following command in your working directory using shell/cmd

bower install ngdropzone
  1. Include angular.js and dropzone.js, dropzone.css from bower_components.
  2. Include ng-dropzone.min.js from dist folder of ng-dropzone package inside bower_component.
  3. You can also include ng-dropzone.min.css but it's not necessary. I have overridden some ugly looking css from dropzone.css

β†’ Install manually

Step 1

You must have AngularJS library included for this directive to work : Download from Google CDN

Step 2

You need to download dropzone.js and dropzone.css files from dropzone repository : Get from official release

Step 3

Download ng-dropzone.min.js from this official release

Step 4

Include above files in <head></head> section of your html page


2. Create .js file and set Dropzone.autoDiscover to false

//Add below line at the top of your JavaScript code
Dropzone.autoDiscover = false;
//This will prevent Dropzone to instantiate on it's own unless you are using dropzone class for styling

3. Configure your angular app

Include thatisuday.dropzone module inside your angular app.

var myNgApp = angular.module('myAppName', ['thatisuday.dropzone']);

####β›ΉOptional

You can configure dropzone before an app starts running. ng-dropzone comes with built in dropzoneOps provider to configure dropzone options which can be implemented as below. setOptions function will set default options fot all your dropzone instances in that app.

myNgApp.config(function(dropzoneOpsProvider){
	dropzoneOpsProvider.setOptions({
		url : '/upload_url',
		maxFilesize : '10',
		...
	});
});

####β›ΉOptional

You can also add default options in dropzoneOps provider (ng-dropzone.min.js) inside defOps object. This is very helpful in case you have multiple apps. But it is not recommended because if you upgrade this directive in future, your app might not behave the way it should.


4. Create dropzone(s)

You can create dropzone using ng-dropzone attribute or <ng-dropzone></ng-dropzone> element.

<div class="dropzone" options="dzOptions" callbacks="dzCallbacks" methods="dzMethods" ng-dropzone></div>

OR

<ng-dropzone class="dropzone" options="dzOptions" callbacks="dzCallbacks" methods="dzMethods"></ng-dropzone>

options attribute specifies model that will set options (click to see) for dropzone and will override any options that may have been provided with dropzoneOps provider. For example, $scope.dzOptions = {bla:bleh,...};

callbacks attribute specifies model that will handle events (click to see) for dropzone. For example, $scope.dzCallbacks.addedfile = function(file){//do something};

methods attribute specifies model that will set methods (click to see) for dropzone. For example, $scope.dzMethods.removeFile(file); or <button ng-click="dzMethods.removeAllFiles();">...</button>

As per above example, dzOptions is model that set options for dropzone, dzCallbacks is model that handles events for dropzone while dzMethods is gateway model that triggers dropzone methods.


5. Configure dropzone(s)

callbacks are not necessary for your dropzone to work, these are just events that you may need as a callback for certain activities of your dropzone. But options must be given inside your controller unless you are configuring it from dropzoneOps provider. url field in dropzone options is mandatory.

myNgApp.controller('main', function($scope){
	//Set options for dropzone
	//Visit http://www.dropzonejs.com/#configuration-options for more options
	$scope.dzOptions = {
		url : '/alt_upload_url',
		paramName : 'photo',
		maxFilesize : '10',
		acceptedFiles : 'image/jpeg, images/jpg, image/png',
		addRemoveLinks : true,
		...
	};
	
	
	//Handle events for dropzone
	//Visit http://www.dropzonejs.com/#events for more events
	$scope.dzCallbacks = {
		'addedfile' : function(file){
			console.log(file);
			$scope.newFile = file;
		},
		'success' : function(file, xhr){
			console.log(file, xhr);
		},
		...
	};
	
	
	//Apply methods for dropzone
	//Visit http://www.dropzonejs.com/#dropzone-methods for more methods
	$scope.dzMethods = {};
	$scope.removeNewFile = function(){
		$scope.dzMethods.removeFile($scope.newFile); //We got $scope.newFile from 'addedfile' event callback
	}
});

By default, dropzone starts file upload when file is dropped or added to the list. But this can be prevented using autoProcessQueue:false in options. Then you have to manually start file upload using dzMethods model. You just have to call function dzMethods.processQueue(); to start upload.

For better understanding, βš‘ checkout source code in /test/test.html file or visit second example in preview of this directive.

I have added two more extra methods getDropzone and getAllFiles which returns dropzone instance and dropzone files respectively. These methods do not accept any arguments and only work with ng-dropzone.

If $scope.dzMethods.method throws undefined error, wrap it in $timeout(function(){...}). This happens because you are referencing an object that is empty as dropzone is not yet property linked with the controller scope.


6. Buffer paste

use ng-buffer-dropzone for image buffer paste on dropzone.


7. Complaints & Contribute

  1. Feel free to create as many issues as you want to report bugs.
  2. Take a fork and create pull request for bug fixes and enhancements.
  3. Please raise an issue if dropzone.js have new updates.

Updates

  1. Version 2.0.0 out
  2. Lesson on how to mock files from server into your dropzone : Wiki here Preview here

Liked it? Give it a star 🌟. I would love it :)

More Repositories

1

commando

An easy-to-use command-line application builder.
Go
137
star
2

ng-image-gallery

πŸŽ₯ Probably the best angular inline and modal image gallery combined...
CSS
77
star
3

catage

Node package and CLI tool to convert code into an image with syntax highlighting
JavaScript
55
star
4

webpack-scp-demo

Webpack SplitChunksPlugin Demo
JavaScript
47
star
5

curved-menu

VanillaJS fully configurable curved menu (circular navigation)
JavaScript
35
star
6

go-cross-build

GitHub Action to build Go (Golang) modules.
Go
34
star
7

tree

List contents of a directory in tree-like format.
Go
18
star
8

clapper

A better command-line arguments parser library for Go.
Go
18
star
9

npm-sharper

πŸ“· Automatic image processor middleware built on top of sharp and multer for express.
JavaScript
17
star
10

dot-matrix-lcd

A simple Dot Matrix LCD emulator for JavaScript
JavaScript
16
star
11

indian-cities-database

Database of Indian cities and their states for node applications
JavaScript
15
star
12

indian-pincode-database

Database of Indian pin (postal) codes for node applications
JavaScript
12
star
13

ngx-password-toggle

Angular 4+ directive to show/hide password
TypeScript
11
star
14

npm-time-ago

Simple time ago function for node that actually works!
JavaScript
11
star
15

npm-no-avatar

Module and Express middleware to generate avatar image with initials
JavaScript
8
star
16

ng-spin

⏰ $http interceptor spinner for angular.js
CSS
8
star
17

ng-http-progress

YouTube like top attached progress bar to show $http requests in progress (automatic)
JavaScript
6
star
18

woggle

A simple command line tool to generate pug, sass, gulp and browser-sync based front-end projects.
JavaScript
5
star
19

ng-modal

AngularJS Modal Directive - Simple and highly customizable modal with photo gallery support.
JavaScript
5
star
20

ng-notif

πŸ™Œ AngularJs slick notification service
CSS
4
star
21

ng-win10-notif

Windows 10 style sticky notification service for angular.js
JavaScript
4
star
22

react-transition-group-learning

Working with react transition group and anime.js
JavaScript
3
star
23

ngx-gradients

A set of cool gradient background for Angular 4
TypeScript
2
star
24

ng-full-modal

Probably the best angular responsive modal service...
JavaScript
2
star
25

ng-buffer-dropzone

πŸ“Ž Extended version of ng-dropzone with buffer paste option
JavaScript
2
star
26

file-checksum

A CLI tool to calculate the checksum of file's content using md5 or sha1 algorithms.
JavaScript
1
star
27

node-gitmeet-template

πŸ“– Simple plug-n-play [github style] markdown blog website on/for node.js
JavaScript
1
star
28

ngx-choices

Angular 4+ typehead to search and select multiple tags
TypeScript
1
star
29

ng-scroll-progress

Angular progress bar for amount of page scrolled
JavaScript
1
star
30

jquery-page-reaction

a jQuery plugin to report user page interactions with web-ui using web-sockets
JavaScript
1
star
31

ng-ui-stater

πŸ”­ ui-router helper directive to generate class, attribute or id field based on state name a ui-view directive posseses...
JavaScript
1
star
32

ng-splash

splash screen for a angular application
HTML
1
star
33

quick-library

A CLI tool to generate React, Angular, Vue library (React for now)
JavaScript
1
star
34

npm-droidcon

Android Drawable Material Icon Downloader | Unpack icons from command line
JavaScript
1
star