spoonconsulting / cordova-plugin-background-upload

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

Unknown error in Android 10 #89

Closed albertleao closed 1 year ago

albertleao commented 4 years ago

Used to work just fine, but now identical code always returns the following in my error handler

{id: "20200415_210326.mp4", error: "upload failed"}

Followed by

{id: "20200415_210326.mp4", error: "execute failed", state: "FAILED"}

These are the parameters I pass into the startUpload method:


"settings": {
"filePath": "file:///storage/emulated/0/DCIM/Camera/20200415_210326.mp4"
"id": "20200415_210326.mp4"
"parameters": {
      "Content-Type": "multipart/form-data"
      "X-amz-algorithm": "AWS4-HMAC-SHA256"
      "X-amz-credential": "omitted"
      "X-amz-date": "20200505T225904Z"
      "X-amz-signature": "omitted"
      "acl": "private"
      "key": "216781588719190015_${filename}"
      "policy": "omitted"
      "success_action_status": "201"
   }
"serverUrl": "https://s3.amazonaws.com/mybucket"
}

Running android 10 on a Samsung Galaxy s10+

I'm wondering if it has to do with this: https://stackoverflow.com/a/58934803/2093658

EDIT: After digging in and trying to do a file upload with the regular cordova plugin, i found that using the same uri that this plugin uses results in a "permissions error" This is most likely to do with android 10 scoped storage.

ombr commented 4 years ago

Hi @albertleao could you try this branch ? https://github.com/spoonconsulting/cordova-plugin-background-upload/pull/84 and let us now if you are having the same issue ? Thanks.

albertleao commented 4 years ago

@ombr Hey! I'll be able to test this tonight and let you know.

albertleao commented 4 years ago

@ombr Unfortunately that branch did not work. I had the following error on upload:

FileTransferManager.js:11 Uncaught (in promise) Error: event handler must be a function
    at new FileTransferManager (FileTransferManager.js:11)
    at Object.init (FileTransferManager.js:89)

To get the plugin installed, I also had to download that branch locally and remove the <edit-config> for the Android:Name for there not to be any clashes.

koczka commented 3 years ago

I have the exact same issue. Any updates on the fix? Though it works some time from an android emulator with api 29, but never on an actual device.

ombr commented 3 years ago

Hi @albertleao @koczka, we are still working on the new version.

Could you try this branch ? afnetworking-spx-demo

We will replace the current master with this new version in a few week.

koczka commented 3 years ago

Sure, I'm going to try it right now.

Edit, can't install from this branch.

Failed to install 'cordova-plugin-background-upload': Error: There was a conflict trying to modify
attributes with <edit-config> in plugin cordova-plugin-background-upload. The conflicting plugin,undefined,
already modified the same attributes. The conflict must be resolved before
cordova-plugin-background-upload can be added. You may use --force to add
the plugin and overwrite the conflicting attributes.  
at PlatformMunger.add_plugin_changes (project/node_modules/cordova-common/src/ConfigChanges/ConfigChanges.js:150:19)
    at project/node_modules/cordova-common/src/PluginManager.js:123:29
    at _fulfilled (project/node_modules/q/q.js:834:54)
    at project/node_modules/q/q.js:863:30
    at Promise.promise.promiseDispatch (project/node_modules/q/q.js:796:13)
    at project/node_modules/q/q.js:857:14
    at runSingle (project/node_modules/q/q.js:137:13)
    at flush (project/node_modules/q/q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:61:11). 
There was a conflict trying to modify attributes with <edit-config> in plugin cordova-plugin-background-upload. The conflicting plugin, undefined, already modified the same attributes. The conflict must be resolved before cordova-plugin-background-upload can be added. You may use --force to add the plugin and overwrite the conflicting attributes.
ombr commented 3 years ago

I think you will need to remove your platform and plugin directory and restart a build.

koczka commented 3 years ago

It still fails with the same error on a full clean platform install.

Here's my plugin config:

<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="cordova-plugin-statusbar" spec="^2.4.2" />
<plugin name="cordova-plugin-device" spec="^2.0.2" />
<plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />
<plugin name="cordova-sqlite-storage" spec="^4.0.0" />
<plugin name="cordova-plugin-local-notification" spec="^0.9.0-beta.2" />
<plugin name="cordova-plugin-screen-orientation" spec="^3.0.2" />
<plugin name="cordova-plugin-add-swift-support" spec="^2.0.2" />
<plugin name="cordova-plugin-file" spec="^6.0.2" />
<plugin name="cordova-plugin-ionic-webview" spec="^4.1.3">
  <variable name="ANDROID_SUPPORT_ANNOTATIONS_VERSION" value="27.+" />
</plugin>
<plugin name="cordova-plugin-inappbrowser" spec="^3.2.0" />
<plugin name="cordova-plugin-camera" spec="^4.1.0">
  <variable name="ANDROID_SUPPORT_V4_VERSION" value="27.+" />
</plugin>
<plugin name="cordova-plugin-uniquedeviceid" spec="^1.3.2" />
<plugin name="cordova-plugin-advanced-http" spec="^2.4.1">
  <variable name="OKHTTP_VERSION" value="3.10.0" />
</plugin>
<plugin name="cordova-plugin-sequence-order-imagepicker" spec="^1.0.3">
  <variable name="ANDROID_SUPPORT_V7_VERSION" value="27.+" />
  <variable name="PHOTO_LIBRARY_USAGE_DESCRIPTION" value=" " />
</plugin>
<plugin name="cordova-plugin-background-upload" spec="~2.0.2" />
ombr commented 3 years ago

I will check on my side and get back to you when we have a new version fixing this.

koczka commented 3 years ago

Thank you for your time! Do you have any updates on this case?

sc-nick commented 3 years ago

Try

<plugin name="cordova-plugin-background-upload" spec="https://github.com/spoonconsulting/cordova-plugin-background-upload.git#afnetworking-spx-demo" />

instead of

<plugin name="cordova-plugin-background-upload" spec="~2.0.2" />

in your config.xml

koczka commented 3 years ago

Thanks, I was able to install the plugin this way, I'm gonna check the function to see if the uploads are working.

Now there's a new error happening:

Android Oreo requires a notification configuration…ml#startForegroundService(android.content.Intent)
sc-nick commented 3 years ago

Does the notification appear? Pls paste your entire config.xml

koczka commented 3 years ago

I had the showNotification set to false, and I got the error above. I set notifications to true, and it did show up in the notification centre, but now I get the execute failed error again.

{id: "pic-6", error: "execute failed", state: "FAILED"}
My config.xml ``` ```
koczka commented 3 years ago

I set showNotification to true as I stated above, but then I get the original execute failed error again.

sc-nick commented 3 years ago

Ok, so paste your upload config because I can't reproduce the error (parameters you pass into startUpload)

koczka commented 3 years ago

Here's an upload object

{
  id: `pic-${idx}`,
  filePath: path,
  fileKey: 'files',
  showNotification: true,
  serverUrl: url,
  headers: {
    Authorization: this.token
  },
    parameters: {
    gid: this.galId
  }
}
sc-nick commented 3 years ago

It should work, please check the demo in case you missed something. Let me know if you get the same error with the demo.

koczka commented 3 years ago

The uploads are working now, but I can't seem to get the event callback to fire.

sc-nick commented 3 years ago

More details pls

koczka commented 3 years ago

I'm using the init function from the demo you linked in your previous command, but I can't see any logs about the events. I'm testing on a huawei mate 10 pro, connected to chrome inspect.

sc-nick commented 3 years ago

The event is null?

koczka commented 3 years ago

No, it simply doesn't get called.

sc-nick commented 3 years ago

Could you paste your init?

koczka commented 3 years ago

It's literally copied from the demo, but there you go

Init code ``` init() { console.log('file uploader init'); this.uploader = FileTransferManager.init( { parallelUploadsLimit: 2, notificationTitle: 'Upload service', notificationContent: 'Background upload service running' }, event => { console.log('EVENT'); var correspondingMedia = this.getMediaWithId(event.id); if (!correspondingMedia) { return; } if (event.state == 'UPLOADED') { console.log('upload: ' + event.id + ' has been completed successfully'); console.log(event.statusCode, event.serverResponse); correspondingMedia.updateStatus('uploaded successfully'); } else if (event.state == 'FAILED') { if (event.id) { console.log('upload: ' + event.id + ' has failed'); correspondingMedia.updateStatus('Error while uploading'); } else { console.error('uploader caught an error: ' + event.error); } } else if (event.state == 'UPLOADING') { console.log('uploading: ' + event.id + ' progress: ' + event.progress + '%'); correspondingMedia.updateStatus('uploading: ' + event.progress + '%'); } if (event.eventId) this.uploader.acknowledgeEvent(event.eventId); } ); } ```
koczka commented 3 years ago

Yeah, the upload works fine, but no status updates whatsoever. It's running android 8.0.0

sc-nick commented 3 years ago

I tested it with the same android version and it works, no error in chrome inspect?

sc-nick commented 3 years ago

Try to init once platform is ready

this.platform.ready().then(() => { ... });

koczka commented 3 years ago

No error, nor any warning. It runs after platform.ready()

ombr commented 3 years ago

@koczka did you manage to make it work the way you want ? Did you manage to make the demo work on your side ? Thanks.