spoonconsulting / cordova-plugin-background-upload

Cordova plugin for background upload
Apache License 2.0
49 stars 53 forks source link

this.uploader.on(...) is not a function #272

Open matheusvps opened 8 months ago

matheusvps commented 8 months ago

Hello, currently using V4 on my project. Did this :

    this.uploader.startUpload(payload);
    console.debug(this.uploader.acknowledgeEvent);
    this.uploader.on('event', (event) => {
      console.debug(event, 'evento do on');
    });
    this.uploader.acknowledgeEvent('blablablaa', (event) => {
      console.debug('sucess', event);
    }, (error) => {
      console.debug('error', error);
    });

Obs : the object uploader is initialized when my app is mounted. The acknowledgeEvent returns "sucess OK" but the "this.uploader.on(...)" returns on is not a function. I need to hear the events clearly because the startUpload is called when I click a button but my documents isn't sended and I got none on my network... Do I need to downgrade my plugin version ? How can I fix that ?

zfir commented 8 months ago

Hello @matheusvps,

For V4, we don't listen on event.

Here is an example how we listen to the callback.

FileTransferManager.init(
        { parallelUploadsLimit: 2 },
        (upload) => {...});

The callback is in the initialiser.

matheusvps commented 8 months ago

Hello @zfir ! Got it, did something like this :

this.uploader = FileTransferManager.init({ parallelUploadsLimit: 1 }, async event => {
        console.debug('initialized');
        if (event.eventId) {
          console.debug('new event was fired', event);
            if (event.state === 'UPLOADED') {
              Vue.prototype.$event.$emit('upload-success', {
                docId: event.eventId,
              });
            } else if (event.state === 'FAILED') {
              Vue.prototype.$event.$emit('upload-error', {
                docId: event.eventId,
              });
            } else if (event.state === 'UPLOADING') {
              Vue.prototype.$event.$emit('upload-progress', {
                docId: docId,
                progress: Math.round(event.progress),
              });
            }

But when I call the .startUpload function, no events are fired, no network updates... and the uploader object is already initialized.

zfir commented 8 months ago

Hello @matheusvps,

This can be due to the payload that you are sending. Can you send a payload example.

Also to see if you are having a problem with plugin, you can use Android Studio to debug.