spoonconsulting / cordova-plugin-background-upload

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

Upload fails silently when using cordova-labs-local-webserver on iOS #229

Closed dennismuench closed 1 year ago

dennismuench commented 1 year ago

Some project setups will not produce file:// urls when FileEntry.toURL is called within startUpload to prepare the payload.filePath.

https://github.com/spoonconsulting/cordova-plugin-background-upload/blob/867ecd2720d2c5b2fa453f4531d02165c1387adf/www/FileTransferManager.js#L54

This will at least be the case when using cordova-labs-local-webserver or any other local web-server.

Because of that, the protocol is not stripped as intended and the filePath remains unchanged. It is then being aggressively turned into an invalid file url within addUpload

https://github.com/spoonconsulting/cordova-plugin-background-upload/blob/867ecd2720d2c5b2fa453f4531d02165c1387adf/src/ios/FileUploader.m#L85

Which will result in an url like this:

file:///http:/localhost:49000/local-filesystem/var/mobile/Containers/Data/Application/54452A4D-B041-4493-A5CF-D4A9F8FEDA13/Documents/file-mirror/0c891b87df87fcedb2a800b7a6d8855cc7e35179.jpeg

And because file errors are not being catch-ed within tempFilePathForUpload, uploads will fail without dispatching an event.

https://github.com/spoonconsulting/cordova-plugin-background-upload/blob/867ecd2720d2c5b2fa453f4531d02165c1387adf/src/ios/FileUploader.m#L137

dennismuench commented 1 year ago

I prepared a pull request with a simple fix which solved this issue for me. It should cover any variations (so far) as well as the use of cordova-labs-local-webserver. Tested on iOS and Android.

payload.filePath = new URL(entry.toURL()).pathname.replace(/^\/local-filesystem/, '')
zfir commented 1 year ago

Hello @dennismuench,

I will do some tests and revert back to you.

Regards, Zafir.