I'm using Dropzone with Angular through ngx-dropzone-wrapper.
I'm not using upload directly from Dropzone, I just let it collect the files and then I process them in my code.
I need to limit file count to 1. So I set config.maxFiles = 1
. Indeed, now file open dialog allows to select single file only. But the problem is that Dropzone does not replace previous file! Instead, it adds the new file to its files collection with accepted=false (most probably, because maxFiles was reached) flag. That's not what I expected. I need config.maxFiles = 1
to remove the old file and add the new and accept it.
So, I should call removeAllFiles(true)
to support my requirements. But I can't find any event handlers that are triggered right after user has chosen a file and before Dropzone attempts to process it.
So, how do I implement the following requirement:
- the user can select only one file at a time
- if the user made a mistake and wants to select another file, the new file should replace the previously selected one
?
<div [dropzone]="config" (maxFilesReached)="maxFilesReached($event)" class="dropzone-top-layer"></div>
and then have a function in my Angular component:public maxFilesReached(event: any): void { this.dropzone.dropzone().removeAllFiles(true); }
– Marraaccept: this.localAcceptHandler
. Inside that function, I manually add file to my own collection ` this.files = [file];` . I have the variablepublic files: any = [];
And later I use myfiles
instead ofthis.dropzone.dropzone().files
. To be honest, Dropzone has also some other unpleasant quirks (difficult to show progress while loading file blobs in memory, buggy integration with MatDialog showing twice for no reason) and I won't use it in my next project. – Marra