Repository navigation
feat(android): upload shared files to host over SFTP - #67
Conversation
Accept SEND/SEND_MULTIPLE file intents, cache them locally, and enqueue uploads through the existing SFTP queue with session or Connect-and-upload pickers. Co-authored-by: Cursor <cursoragent@cursor.com>
Reviewer's GuideData structuresIntroduce the shared-file payload and classify file shares ahead of accompanying text so downstream handlers receive the intended data.
APIExpose named SFTP uploads and add the Android method-channel bridge for retrieving cached files from incoming share intents.
Uses of the APIConnect the share-file events and cold-start payload to the upload handler, and enqueue pending uploads after the SFTP directory initializes.
ImplementationImplement share-to-host orchestration, including connected-session selection, profile connection, upload preparation, and the associated picker flows.
Capture SEND and SEND_MULTIPLE streams, copy each URI to cache without buffering whole files, and resolve safe display filenames.
UIRegister Android file-share MIME intent filters so the app appears as a target for single- and multi-file shares.
ConfigurationDocument Android share-intent routing and the new share-to-host feature in repository guidance and release notes.
DocumentationDescribe share-to-host in the README and mark the corresponding suggestion as shipped.
TestsVerify named upload destinations, share-payload precedence, shared-file parsing, upload eligibility, and conversion to named upload items.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
| return uri.lastPathSegment | ||
| } | ||
|
|
||
| private fun sanitizeFileName(name: String): String { |
There was a problem hiding this comment.
WARNING: Filename sanitization incomplete for Windows hosts
sanitizeFileName only replaces / and \ with _. Windows also forbids :, *, ?, ", <, >, | in filenames. Shared files with these characters will fail to upload to Windows hosts.
| private fun sanitizeFileName(name: String): String { | |
| private fun sanitizeFileName(name: String): String { | |
| val trimmed = name.trim().ifEmpty { "shared_file" } | |
| return trimmed.replace(Regex("[\\/:*?\"<>|]+"), "_") | |
| } |
| } | ||
| } | ||
| Intent.ACTION_SEND_MULTIPLE -> { | ||
| val streams = readMultipleStreams(intent) |
There was a problem hiding this comment.
WARNING: Stale state on empty SEND_MULTIPLE
If readMultipleStreams returns an empty list, the function returns early without clearing sharedText or sharedFiles. This leaves stale share data that could be processed incorrectly on the next intent.
| val streams = readMultipleStreams(intent) | |
| Intent.ACTION_SEND_MULTIPLE -> { | |
| val streams = readMultipleStreams(intent) | |
| if (streams.isEmpty()) { | |
| sharedText = null | |
| sharedFiles = null | |
| return | |
| } |
| "path" to outFile.absolutePath, | ||
| "name" to safeName, | ||
| ) | ||
| } catch (_: Exception) { |
There was a problem hiding this comment.
SUGGESTION: Log exception for debugging
Catching all exceptions without logging makes it difficult to diagnose share failures in production. At minimum, log the exception.
| } catch (_: Exception) { | |
| } catch (e: Exception) { | |
| android.util.Log.w("ShareIntent", "Failed to copy shared file", e) | |
| if (outFile.exists()) { | |
| outFile.delete() | |
| } | |
| null | |
| } |
| final SSHProvider ssh = Provider.of<SSHProvider>(context, listen: false); | ||
| final List<SessionEntry> connected = connectedSessions(ssh); | ||
|
|
||
| onTabSelected?.call(AppTab.client); |
There was a problem hiding this comment.
SUGGESTION: Switch tab only after validating upload can proceed
onTabSelected?.call(AppTab.client) is called before checking for connected sessions or available profiles. If no profiles exist, the tab switches but an error snackbar is shown, leaving the user on the Client tab with no actionable session.
Move the tab switch inside the success paths, or guard it with a check that upload will proceed.
| if (controller == null) { | ||
| return; | ||
| } | ||
| await controller.init(); |
There was a problem hiding this comment.
WARNING: Upload attempted even if controller.init() fails
_bootstrap calls await controller.init() but doesn't check controller.error before proceeding to uploadNamedFiles. If init fails (e.g., no drives, connection issue), the upload will still be attempted and likely fail confusingly.
| await controller.init(); | |
| await controller.init(); | |
| if (controller.error != null || !mounted) { | |
| return; | |
| } |
|
|
||
| _controller = SftpController(client: client); | ||
| unawaited(_controller!.init()); | ||
| unawaited(_bootstrap()); |
There was a problem hiding this comment.
SUGGESTION: Handle potential race in initState
unawaited(_bootstrap()) in initState means _bootstrap runs asynchronously. If the widget is disposed before _bootstrap completes, the mounted checks inside _bootstrap handle it, but consider using a StreamSubscription or Future-based pattern for clearer lifecycle management.
Summary
ACTION_SEND/SEND_MULTIPLEfile shares, stream content URIs into app cache, and upload via the existing SFTP transfer queue.Related issues
N/A (release-batch item from suggestions 7.5)
Type of change
Platform tested
Hermetic
flutter analyze+ targeted unit tests locally; device share-sheet still needs a manual APK install.Test plan
flutter pub getflutter analyze(no errors)flutter testSteps:
Screenshots / recordings
N/A (device share-sheet verification pending)
Checklist
analysis_options.yamlMade with Cursor
Summary by Sourcery
Support sharing files from Android apps directly to a host through the existing SFTP transfer workflow.
New Features:
Enhancements:
Documentation:
Tests: