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

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

Closed
Akoszewski opened this issue Sep 10, 2019 · 9 comments
Labels
bug Something isn't working

Comments

@Akoszewski
Copy link

Akoszewski commented Sep 10, 2019

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

Nico04 commented Sep 14, 2019

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

@Nico04
Copy link

Nico04 commented Sep 14, 2019

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...

@shaqian shaqian added the bug Something isn't working label Sep 20, 2019
@sjagat
Copy link

sjagat commented Sep 23, 2019

@Nico04 , your changes will not allow progress of upload or download to be seen. Please try sjagat@9e10957 patch. I did tried and it works.

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

@Akoszewski
Copy link
Author

@sjagat solution worked for me. Thank you.

@Nico04
Copy link

Nico04 commented Sep 25, 2019

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

@travisjayday
Copy link

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

@shaqian
Copy link
Owner

shaqian commented Oct 13, 2019

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

Thanks,
Qian

@sjagat
Copy link

sjagat commented Oct 13, 2019

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

@shaqian
Copy link
Owner

shaqian commented Nov 28, 2019

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

Thanks,
Qian

@shaqian shaqian closed this as completed Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants