mercredi 3 février 2021

Dropzone js success and error options are not working

I am using Dropzone.js in my ember application. I have implemented file upload functionality. Whenever I upload a file, The file was getting upload in the backend and in the network tab I see 200 OK but the success option is never getting called even though I have mentioned Dropzone.autoDiscover = false;.

Please find the below code for your reference,

import Ember from 'ember';
import config from '../config/environment';

export default Ember.Component.extend({
  images: [],
  targetClass: 'file-upload-drop',
  templateClass: 'file-upload-template',
  url: config.uploadUrl,
  dropzone: undefined,

  onFileUploaded(file) {},
  onRemovedFile(file) {},
  onFileError(file, error) {},

  _createFileModel(file, data) {
    return Ember.Object.extend({
      file: file
    }, data).create();
  },

  didInsertElement() {
    const url = this.get('url'),
      target = this.$(`.${this.get('targetClass')}`).get(0),
      self = this,
      get = Ember.get;

    this.set('register-as', this);

    var dz = new Dropzone(target, {
      url: url,
      addRemoveLinks: true,

      init() {
        var icons = self.get('images') || [];

        icons.forEach((icon) => {
          var file = {
            id: get(icon, 'id'),
            name: get(icon, 'id'),
            size: get(icon, 'size'),
            status: Dropzone.ADDED,
            type: get(icon, 'mimeType')
          };
          this.options.addedfile.call(this, file);
          this.createThumbnailFromUrl(file, `/api/v1/images/view/${file.name}`);
          this.emit("success". file);
          this.emit("complete", file);
          this.files.push(file);
        });

      }
    });

    dz.on('success', (file, response) => {
      console.log('success');
      file.id = response.id;
      this.get('onFileUploaded')(this._createFileModel(file, response));
    });

    dz.on('error', (file, errorMessage, xhr) => {
    errorMessage = errorMessage || {};

      if (errorMessage.message) {
        //Ember.$('.dz-error-message span', file.previewElement).text(errorMessage.message);

        dz.removeFile(file);

        this.get('onFileError')(file, errorMessage.message);
      }
    });

    dz.on('removedfile', (file) => {
    console.log('removedFile');
      //TODO handle when user removes a file from the list
      this.get('onRemovedFile')(file);
    });

    this.set('dropzone', dz);
  }
});

enter image description here

Please find the above image for your reference. The progress bar is always shown and the success method is not getting called. Is there an issue with Jquery compatibility? I am using jQuery:3.4.1. Any help would be really appreciable.




Aucun commentaire:

Enregistrer un commentaire