Steps to work Dropzone with Angular 6 (angular version: 6.1.8)
1. Create angular project using angular CLI and download dropzone dist folder from dropzonejs.com site.
2. Put dropzone.css (from downloaded dist folder) in projects ../src/assets/css folder (if not exists, then create) and import it in styles.css file like following
styles.css
----------
@import "../src/assets/css/dropzone.css";
3. Put dropzone.js (from downloaded dist folder) file in projects ../src/assets/js folder (if not exists, then create) and put the following value in the scripts option of angular.json file:
angular.json
------------
"scripts": [
"src/assets/js/lib/dropzone.js"
]
4. Now, in you component ts file (for example, app.component.ts), define your Dropzone and its options like the following way:
app.component.ts
----------------
import { Component, OnInit } from '@angular/core';
declare var Dropzone: any;
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
ngOnInit(): void {
Dropzone.options.pdfDropzone = {
paramName: 'file',
maxFilesize: 5, // MB
uploadMultiple: true,
autoProcessQueue: true,
init: function () {
this.on('addedfile', function (file) {
const removeButton = Dropzone.createElement('<button class=\'btn btn-sm btn-block\'>Remove file</button>');
const _this = this;
removeButton.addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
_this.removeFile(file);
});
file.previewElement.appendChild(removeButton);
});
}
};
}
}
5. Now, add the following div in the html file:
app.component.html
------------------
<div>
<form action="http://localhost:8080/api/upload/file"
class="dropzone dz-clickable"
id="pdf-dropzone">
</form>
</div>
Action attribute of form element is the url where dropzone will upload the file.
It works for me. Cheers!!