0

Iam using dropzone for uploading image into a webApi from angular 4 application on button click event. mydrpzone.processQueue() is not working . On upload button click I got this error this.drpzone.processQueue is not a function.

Here is my code

app.component.ts

import { Component, ViewChild } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { DropzoneModule, DropzoneComponent, DropzoneDirective, 
DropzoneConfigInterface } from 'ngx-dropzone-wrapper';


@Component({
selector: 'my-app',
templateUrl: `./app.component.html`,
styleUrls: ['./app.component.css']
})
export class AppComponent {

UsreName: string = "Midhun";
@ViewChild('drpzone') drpzone: DropzoneConfigInterface;



myFiles: string[] = [];
sMsg: string = '';

getFileDetails(e: any) {

    //console.log (e.target.files);
    for (var i = 0; i < e.target.files.length; i++) {
        this.myFiles.push(e.target.files[i]);
    }


}

onSending(data: any): void {
    // data [ File , xhr, formData]
    const file = data[0];
    const formData = data[2];
    formData.append('Name', "Midhun");
    console.log("enetered");
}

uploadFiles() {
    //this.drpzone.processQueue();
    this.drpzone.processQueue();
    console.log("uploading...");
}

onSendingmultiple() {

}

onError() {

}
onSuccess() {

}


//public type: string = 'component';
public type: string = 'directive';

public config: DropzoneConfigInterface = {
    url: 'http://localhost:60945/api/fileupload/',
    //url: 'http://localhost:60945/user/PostUserImage',
    //url:'https://httpbin.org/post',
    maxFiles: 5,
    clickable: true,
    acceptedFiles: 'image/*',
    createImageThumbnails: true,
    autoProcessQueue: false,
    addRemoveLinks: true,

};

constructor() { }


}

app.component.html

<div class="text-center well">
            <dropzone [config]="config" #drpzone
                      [message]="'Click or drag images here to upload'"
                      (error)="onError($event)"
                      (sending)="onSending($event)"
                      (sendingmultiple)="onSendingmultiple($event)"
                      (success)="onSuccess($event)">
            </dropzone>
        </div>
        <br />
        <button (click)="uploadFiles()">Upload</button>

please help if anybody know how to fix it.

1 Answer 1

1

Just googled it, and that's what I found: The directive itself is not the Dropzone instance, so for 4.x this.dropzone.dropzone.processQueue() or for 5.x this.dropzone.dropzone().processQueue().

Took here: https://github.com/zefoy/ngx-dropzone-wrapper/issues/60

By the way, I'm not sure, but this seems incorrect @ViewChild('drpzone') drpzone: DropzoneConfigInterface;

shouldn't it be @ViewChild('drpzone') drpzone: DropzoneDirective; ?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your reply. but it is not working.. I have scene that code before. It gives me this error ERROR TypeError: Cannot read property 'processQueue' of undefined
did you found something ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.