File Sharing App
Implement fast, resumable, and verifiable file transfers. Pair the transfer protocol with explicit user consent and strong validation.
1) Design the transfer flow
- User selects a file
- Sender sends a small “offer” message (name/size/hash)
- Receiver accepts/declines
- Start a FileTransfer with TransferOptions
2) Choose TransferOptions
- Use resumable transfers on mobile networks.
- Enable integrity verification for user-visible files.
- Pick chunk size based on throughput vs resume granularity.
val options = TransferOptions(
chunkSizeBytes = 256 * 1024,
resumeEnabled = true,
verifyIntegrity = true
)
3) Progress UI
val transfer = p2p.sendFile(peerId, file, options)
transfer
.onProgress { p -> updateProgress(p) }
.onComplete { ok -> notifyComplete(ok) }
4) Safety checklist
- Validate filenames and types; never auto-open files.
- Bound total disk usage and per-peer transfer rate.
- Require explicit accept on receiver before transfer begins.
- Log transfer failures with trace IDs for support.