shaqian / flutter_ssh

SSH and SFTP client for Flutter
https://pub.dartlang.org/packages/ssh
MIT License
117 stars 83 forks source link

"@UiThread must be executed on the main thread" exception while uploading to SFTP server #15

Closed Akoszewski closed 4 years ago

Akoszewski commented 5 years ago

I tried to upload a file but after successfull connect and connectSFTP I got a strange exception while trying to sftpUpload. I found info that many plugins had such issue and needed a fix.

E/SshPlugin(26101): Failed to upload /data/user/0/com.example.picker/app_flutter/file0.jpg E/flutter (26101): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: PlatformException(upload_failure, java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Thread-8, null) E/flutter (26101): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:564:7) E/flutter (26101): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:316:33) E/flutter (26101): E/flutter (26101): #2 SSHClient.sftpUpload (package:ssh/ssh.dart:185:33) E/flutter (26101): E/flutter (26101): #3 MyApp.sendPhotos (package:picker/main.dart:126:24) E/flutter (26101): E/flutter (26101): #4 MyApp.build. (package:picker/main.dart:74:22) E/flutter (26101): #5 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14) E/flutter (26101): #6 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:711:32) E/flutter (26101): #7 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter (26101): #8 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11) E/flutter (26101): #9 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7) E/flutter (26101): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9) E/flutter (26101): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13) E/flutter (26101): #12 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11) E/flutter (26101): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19) E/flutter (26101): #14 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter (26101): #15 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) binding.dart:102:7) E/flutter (26101): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gesturesE/flutter (26101): #18 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter (26101): #19 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter (26101): #21 _invoke1 (dart:ui/hooks.dart:250:10)

Nico04 commented 5 years ago

Same issue here, any workaround ? v0.0.4, Flutter v1.9.1

Nico04 commented 5 years ago

After some digging, I found out that the file was actually successfully uploaded, despite the error.

Fortunately I found a workaround : On SshPlugin.java, line 491, change this line :

channelSftp.put(path, toPath + '/' + (new File(path)).getName(),
              new progressMonitor(args.get("id").toString(), "UploadProgress"), ChannelSftp.OVERWRITE);

To this : channelSftp.put(path, toPath + '/' + (new File(path)).getName(), ChannelSftp.OVERWRITE);

It removes the progress handler, which is sad, but then it works fine :) As I don't know java at all, I have no clues how to really fix it...

sjagat commented 5 years ago

@Nico04 , your changes will not allow progress of upload or download to be seen. Please try https://github.com/sjagat/flutter_ssh/commit/9e109577c6a7b8272d2159b4b86b6fe46f5c194f patch. I did tried and it works.

@shaqian , Please use above patch if you agree. I did validate it and it does work.

Akoszewski commented 5 years ago

@sjagat solution worked for me. Thank you.

Nico04 commented 5 years ago

@sjagat your patch worked for me also, thanks :)

travisjayday commented 5 years ago

Could this patch get pushed to master soon? @sjagat. It works for me too!

shaqian commented 5 years ago

Thanks @sjagat and sorry for the delay. The fix for eventSink is released in v0.05.

Thanks, Qian

sjagat commented 5 years ago

@shaqian Great !!! Thank you. Will try out soon ....

shaqian commented 4 years ago

Archiving the thread. Feel free to reopen if the issue persists.

Thanks, Qian