Home / Companies / Stream / Blog / Post Details
Content Deep Dive

Adventures in Tracking Upload Progress With OkHttp and Retrofit

Blog post from Stream

Post Details
Company
Date Published
Author
Márton B.
Word Count
2,800
Language
English
Hacker News Points
-
Summary

The text provides a detailed account of refining a file upload progress tracking system using Retrofit and OkHttp, addressing initial usability and UX challenges. The original implementation used a custom `ProgressRequestBody` class and a `ProgressCallback` interface to track upload progress, but faced issues with repeated callbacks due to logging interceptors in debug builds. A workaround involved dynamically skipping progress updates, but this proved complex and unsustainable. The ultimate solution leveraged OkHttp's tagging API to attach callbacks to requests, allowing a `ProgressInterceptor` to wrap the `RequestBody` for progress tracking only at the final stage of the upload process, thus ensuring accurate progress reporting without interference from logging. This implementation, despite some limitations with buffering and network delays, represents a more robust approach to handling file uploads and is documented in the Chat Android SDK's GitHub repository.