Mobile

React Native Android background multipart upload resets to 0% after switching from cellular to Wi‑Fi

Environment

Environment

Android 12 devices running a React Native app using a background uploader library (uploads ~200 MB via multipart POST to company API). App uses a background service but not a foreground persistent notification. Access token expires every 15 minutes; server supports partial uploads only if client provides upload‑session token.

Symptoms

Symptoms

When users switch from 5G to Wi‑Fi mid-upload, the client restarts the upload from 0% and server shows incomplete partial uploads that never continue. This happens consistently when network type changes during transfer.

Observations

Observations

Client logs show HTTP connection closed and then a fresh POST started. No 'resume' or range requests attempted. Android OS sometimes kills background service during handover; no foreground notification present. Server returns 401 when token expired; uploader library does not retry with token refresh flow.

Already attempted

Already attempted

Tried increasing token lifetime, adding retry logic at app layer, and keeping socket alive; still restarts when service is killed by OS. Tested with WorkManager and a foreground service; foreground service prevented kills but server still required resumable protocol.

Question

Question

What causes the multipart upload reset on network change and what are the recommended, safe ways to implement resumable background uploads on Android for React Native?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
erikethernet Answer
user
Posted 4w ago • 0 confirmations

This is usually a combination of Android killing a non‑foreground background uploader during handover and the server not supporting resumable uploads. Fix in two parts: (1) make the Android upload resilient — run it under WorkManager/foreground service so it survives network changes and persists progress to disk; (2) implement a resumable protocol server-side (tus or multipart with upload IDs) so the client can reattach and send the remaining bytes after a restart. Short‑term, promoting uploads to a foreground service and ensuring tokens refresh on 401 will reduce restarts; long‑term, add a true resumable upload API. Both steps are reversible and testable by switching networks mid-upload and confirming progress continues rather than restarting.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 4w ago• Trouble ID

Most likely causes

Upload protocol/server does not support resumable uploads or byte-range continuation 85%
Android kills background uploader on network change (service not promoted to foreground) causing client restart 80%
Access token expiry during long transfer leads server to reject resumed connections 60%

Summary

Two distinct failure paths emerge: 1) Android OS may kill the background upload service on network handoff unless it's a foreground service (causing the uploader to restart), and 2) the upload protocol lacks resumability: without server-side support for chunked/resume (tus, S3 multipart, or session-based byte ranges), the client cannot continue where it left off. Additional contributors include token expiry during long uploads; if the upload session isn't refreshable, a restart is forced. The successful mitigation requires both client-side use of reliable background execution (WorkManager/foreground service) and server-side resumable upload support.

Suggested Fixes

Diagnostic step 1
Implement resumable uploads (tus protocol, or server-side S3 multipart with upload IDs) so the client can reattach and continue at a byte offset when network changes occur.
Diagnostic step 2
Use WorkManager with setForegroundAsync (or a foreground service with persistent notification) for guaranteed long-running uploads across network transitions; test by switching networks and verifying service survives.
Diagnostic step 3
Persist upload progress/state to disk (upload ID, last-completed byte) before making each chunk request so the client can resume after restart.

Continue troubleshooting

Matched from the title, description and tags