Uploading Files to AWS S3 with Progress - Kotlin
Article Summary
Mehmet Gür from Getir tackles a common Android pain point: uploading files to S3 with real-time progress tracking. His solution avoids the MultipartBody pitfalls that trip up most developers.
This practical guide demonstrates how to upload files to AWS S3 from Android using Kotlin Coroutines and Retrofit2. The article focuses on creating a custom RequestBody implementation that enables accurate progress tracking, a critical feature for user experience that's surprisingly tricky to implement correctly.
Key Takeaways
- Custom RequestBody replaces MultipartBody to avoid known S3 upload errors
- CountingSink wrapper tracks uploaded bytes for real-time progress updates
- ActivityResultLauncher handles file selection with modern Android APIs
- ContentResolver accesses file metadata without MultipartBody complexity
A working implementation for S3 file uploads with progress tracking that sidesteps Android's MultipartBody limitations using custom RequestBody and sink wrapping.
About This Article
Android developers run into MultipartBody errors when uploading files to S3, which breaks uploads and leaves teams like Getir scrambling for workarounds.
Mehmet Gür built a custom RequestBody class that wraps a CountingSink to track byte writes as they happen. This approach gives real-time progress callbacks without the MultipartBody headaches.
Developers can now show accurate upload progress by comparing writtenBytes to contentLength and updating a ProgressBar with android:max="100" while files go to S3.