Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matheusvps opened this issue Aug 18, 2023 · 5 comments
Open

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

matheusvps opened this issue Aug 18, 2023 · 5 comments

Comments

@matheusvps
Copy link

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
Copy link
Member

zfir commented Aug 21, 2023

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
Copy link
Author

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
Copy link
Member

zfir commented Aug 22, 2023

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.

@hughknaus
Copy link

hughknaus commented Sep 25, 2024

@zfir I am having the same issue on Android where the uploader is initialized, .startUpload is called, no events fire. This is from Android Studio:

2024-09-26 09:34:47.577 21473-21473 Capacitor/Console       com.mydomain.sa                 D  File: http://localhost/main.js - Line 17742 - Msg: Starting background upload... [object Object]
2024-09-26 09:34:47.577 21473-21473 Capacitor/Plugin        com.mydomain.sa                 V  To native (Cordova plugin): callbackId: File749860358, service: File, action: resolveLocalFileSystemURI, actionArgs: ["http:\/\/localhost\/__cdvfile_files__\/IMPORTED_FILE--3ac1b280-2f2d-4eca-8129-176073c822cb--RESIZED_max"]
2024-09-26 09:34:47.579 21473-21473 Capacitor/Plugin        com.mydomain.sa                 V  To native (Cordova plugin): callbackId: FileTransferBackground749860359, service: FileTransferBackground, action: startUpload, actionArgs: [{"headers":{"Authorization":"Bearer 80d329d1cfa8a203e626865f7cdbc4f5"},"serverUrl":"https:\/\/sa.mydomain.com\/m\/\/sa\/ImageUpload\/334947\/1508634\/","fileKey":"filename","filePath":"\/data\/user\/0\/com.mydomain.sa\/files\/IMPORTED_FILE--3ac1b280-2f2d-4eca-8129-176073c822cb--RESIZED_max","id":"3ac1b280-2f2d-4eca-8129-176073c822cb","notificationTitle":"Uploading Photos...","parameters":{}}]
2024-09-26 09:34:47.580 21473-23526 FileTransferBackground  com.mydomain.sa                 D  startUpload: Starting work via work manager
2024-09-26 09:34:47.589 21473-23526 CordovaBackgroundUpload com.mydomain.sa                 D  eventLabel='Uploader starting upload' uploadId='3ac1b280-2f2d-4eca-8129-176073c822cb'
2024-09-26 09:34:47.607 21473-21759 Compatibil...geReporter com.mydomain.sa                 D  Compat change id reported: 194532703; UID 10333; state: ENABLED
2024-09-26 09:34:47.607 21473-21759 Compatibil...geReporter com.mydomain.sa                 D  Compat change id reported: 253665015; UID 10333; state: ENABLED
2024-09-26 09:34:47.612 21473-21759 ConnectivityManager     com.mydomain.sa                 D  StackLog: [android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:4511)] [android.net.ConnectivityManager.registerDefaultNetworkCallbackForUid(ConnectivityManager.java:5089)] [android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:5056)] [android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:5030)] [androidx.work.impl.utils.NetworkApi24.registerDefaultNetworkCallbackCompat(NetworkApi24.kt:28)] [androidx.work.impl.constraints.trackers.NetworkStateTracker24.startTracking(NetworkStateTracker.kt:139)] [androidx.work.impl.constraints.trackers.ConstraintTracker.addListener(ConstraintTracker.kt:57)] [androidx.work.impl.constraints.controllers.ConstraintController.replace(ConstraintController.kt:82)] [androidx.work.impl.constraints.WorkConstraintsTrackerImpl.replace(WorkConstraintsTracker.kt:92)] [androidx.work.impl.background.greedy.GreedyScheduler.schedule(GreedyScheduler.java:170)] [androidx.work.impl.Schedulers.schedule(Schedulers.java:119)] [androidx.work.impl.utils.EnqueueRunnable.scheduleWorkInBackground(EnqueueRunnable.java:135)] [androidx.work.impl.utils.EnqueueRunnable.run(EnqueueRunnable.java:95)] [androidx.work.impl.utils.SerialExecutorImpl$Task.run(SerialExecutorImpl.java:96)] [java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)] [java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)] [java.lang.Thread.run(Thread.java:1012)]
2024-09-26 09:34:47.645 21473-21759 WM-WorkerWrapper        com.mydomain.sa                 I  Worker result RETRY for Work [ id=22434ea3-c55c-41ed-819a-df7c8905243d, tags={ com.spoon.backgroundfileupload.UploadTask, work_tag_upload, packet_9501a188-96ec-40d9-8122-ff2ecbacfe74 } ]
2024-09-26 09:34:47.649 21473-21473 ConnectivityManager     com.mydomain.sa                 D  StackLog: [android.net.ConnectivityManager.unregisterNetworkCallback(ConnectivityManager.java:5199)] [androidx.work.impl.utils.NetworkApi21.unregisterNetworkCallbackCompat(NetworkApi21.kt:31)] [androidx.work.impl.constraints.trackers.NetworkStateTracker24.stopTracking(NetworkStateTracker.kt:154)] [androidx.work.impl.constraints.trackers.ConstraintTracker.removeListener(ConstraintTracker.kt:73)] [androidx.work.impl.constraints.controllers.ConstraintController.replace(ConstraintController.kt:80)] [androidx.work.impl.constraints.WorkConstraintsTrackerImpl.replace(WorkConstraintsTracker.kt:92)] [androidx.work.impl.background.greedy.GreedyScheduler.removeConstraintTrackingFor(GreedyScheduler.java:243)] [androidx.work.impl.background.greedy.GreedyScheduler.onExecuted(GreedyScheduler.java:229)] [androidx.work.impl.Processor.onExecuted(Processor.java:385)] [androidx.work.impl.Processor$FutureListener.run(Processor.java:484)]
2024-09-26 09:34:48.041 21473-21679 Capacitor/NetworkPlugin com.mydomain.sa                 V  Notifying listeners for event networkStatusChange
2024-09-26 09:34:51.088 21473-21679 Capacitor/NetworkPlugin com.mydomain.sa                 V  Notifying listeners for event networkStatusChange
2024-09-26 09:35:17.657 21473-21473 ConnectivityManager     com.mydomain.sa                 D  StackLog: [android.net.ConnectivityManager.sendRequestForNetwork(ConnectivityManager.java:4511)] [android.net.ConnectivityManager.registerDefaultNetworkCallbackForUid(ConnectivityManager.java:5089)] [android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:5056)] [android.net.ConnectivityManager.registerDefaultNetworkCallback(ConnectivityManager.java:5030)] [androidx.work.impl.utils.NetworkApi24.registerDefaultNetworkCallbackCompat(NetworkApi24.kt:28)] [androidx.work.impl.constraints.trackers.NetworkStateTracker24.startTracking(NetworkStateTracker.kt:139)] [androidx.work.impl.constraints.trackers.ConstraintTracker.addListener(ConstraintTracker.kt:57)] [androidx.work.impl.constraints.controllers.ConstraintController.replace(ConstraintController.kt:82)] [androidx.work.impl.constraints.WorkConstraintsTrackerImpl.replace(WorkConstraintsTracker.kt:92)] [androidx.work.impl.background.greedy.GreedyScheduler.schedule(GreedyScheduler.java:170)] [androidx.work.impl.background.greedy.DelayedWorkTracker$1.run(DelayedWorkTracker.java:75)]
2024-09-26 09:35:17.672 21473-21759 WM-WorkerWrapper        com.mydomain.sa                 I  Worker result RETRY for Work [ id=22434ea3-c55c-41ed-819a-df7c8905243d, tags={ com.spoon.backgroundfileupload.UploadTask, work_tag_upload, packet_9501a188-96ec-40d9-8122-ff2ecbacfe74 } ]
2024-09-26 09:35:17.674 21473-21473 ConnectivityManager     com.mydomain.sa                 D  StackLog: [android.net.ConnectivityManager.unregisterNetworkCallback(ConnectivityManager.java:5199)] [androidx.work.impl.utils.NetworkApi21.unregisterNetworkCallbackCompat(NetworkApi21.kt:31)] [androidx.work.impl.constraints.trackers.NetworkStateTracker24.stopTracking(NetworkStateTracker.kt:154)] [androidx.work.impl.constraints.trackers.ConstraintTracker.removeListener(ConstraintTracker.kt:73)] [androidx.work.impl.constraints.controllers.ConstraintController.replace(ConstraintController.kt:80)] [androidx.work.impl.constraints.WorkConstraintsTrackerImpl.replace(WorkConstraintsTracker.kt:92)] [androidx.work.impl.background.greedy.GreedyScheduler.removeConstraintTrackingFor(GreedyScheduler.java:243)] [androidx.work.impl.background.greedy.GreedyScheduler.onExecuted(GreedyScheduler.java:229)] [androidx.work.impl.Processor.onExecuted(Processor.java:385)] [androidx.work.impl.Processor$FutureListener.run(Processor.java:484)]

And it's in a retry loop.

I should add that file at symlink /data/user/0/com.mydomain.sa/files/IMPORTED_FILE--3ac1b280-2f2d-4eca-8129-176073c822cb--RESIZED_max does exist at /data/data/com.mydomain.sa/files/files/IMPORTED_FILE--3ac1b280-2f2d-4eca-8129-176073c822cb--RESIZED_max (verified using Android Studio's Device Explorer)

Using v4.1.1 with Capcitor 6

@hughknaus
Copy link

I should add that after reviewing the backend logs that there is never a request made to the server for photo uploads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants