Repository navigation
Description
Hi, I'm using react-native-blob-util in a React Native CLI app to download multiple files in parallel. The downloads work perfectly when IOSBackgroundTask is set to false, but when I set IOSBackgroundTask: true, I consistently encounter a problem: some of the downloaded files end up being 0 KB in size, and it's not always the same file. The issue appears to occur randomly.
Can someone help me understand why this is happening, and when should I set IOSBackgroundTask to true? The App I'm building has a requirement to work Offline, that's why I have to download multiple files and store them. It also need to keep downloading the files even when the App is running on background.
Environment:
Library version: react-native-blob-util@^0.19.11
React Native version: 0.76.9
Platform: iOS
Device: Simulator (tested so far)
iOS Version: e.g., iOS 17.5 (simulator)
Development machine: macOS
Steps to reproduce:
Configure the fetch call with IOSBackgroundTask: true.
Initiate multiple file downloads in parallel (e.g., 5–10).
Observe that some files are saved with 0 KB size.
Repeat test — different files result in 0 KB on each run.
Sample Code
const fetchBlob = async (
fileName: string,
fullFilePath: string,
) => {
const authBearerToken = `Bearer token`
const fullApiRoute = 'MyApiEndpoint'
const headers = { Authorization: authBearerToken }
return new Promise<any>((resolve, reject) => {
ReactNativeBlobUtil.config({
path: fullFilePath,
fileCache: true,
indicator: true,
overwrite: true,
IOSBackgroundTask: true, // works when is set to false.
})
.fetch('GET', fullApiRoute, headers)
.then(async res => {
const resStatus = res?.info ? res.info().status : 'Unknown'
const isValidResponse = resStatus === 200 || res.data
if (isValidResponse) {
resolve(res)
}
})
.catch(error => {
reject(error)
})
})
}
// Downloading multiple files in parallel
let successCount = 0
const allPromises = await Promise.all(
filesToFetch.map(file => {
return fetchBlob(file.name, file.pathToDownload)
.then(() => {
successCount++
return 'done'
})
.catch(err => {
console.warn(`Skipping file due to error for ${file.id}:`, err)
return 'error'
})
}),
)

Activity
RonRadtke commentedon Jun 5, 2025
Is the app in the background when the downloads finish?
Do you get a positive response for these files that have 0 bytes?
What happens if you don't use the file cache?
I'm wondering if it maybe downloads the file but since the app is not active it stops the processing and does not handle the finished download correctly
eduardo-santos-tribia commentedon Jun 6, 2025
Hi @RonRadtke , thanks for the reply. Let me try to answer your questions:
1. Is the app in the background when the downloads finish?
No, the App is still running and open when the downloads finish.
2. Do you get a positive response for these files that have 0 bytes?
Yes, the response is HTTP 200 code, but I get an error if I try to load this file.
3. What happens if you don't use the file cache?
Still the same issue, the only way to make my parallel downloads work is setting
IOSBackgroundTasktofalse.4. I'm wondering if it maybe downloads the file but since the app is not active it stops the processing and does not handle the finished download correctly
In my case, I'm not putting the App on Background, even though this is a requirement for my App, I'm still not doing this because I want to ensure and validate that all Downloads work when the app is active first. What I think is happening might be related to the way iOS handles the parallel downloads when IOSBackgroundTask is set to true. I mean, probably there are some limitations by the OS related to the amount of parallel downloads or the size of the downloads, but it's still strange that every time I try this parallel downloads I have a different response. Sometimes all the 6 files are downloaded with correct size and sometimes one and/or another have 0 bytes.
Also, it's strange that the response from react-native-blob-utils is success and valid even if the file was not properly created. I think in this case, something got stuck in the layer between react-native-blob-utils and iOS native, but I'm not sure.
RonRadtke commentedon Jun 8, 2025
Thanks.
Yes something strange is happening... Need to test it locally probably... Or do you have time and the possibility to dig?
I assume that the file is created but either the cache file is empty too, or for some reason the code things it is empty. But why I am not sure...
eduardo-santos-tribia commentedon Jun 10, 2025
Unfortunately, I'll not have time to dig into it since I'm rushing to reach the deadline of the app I'm currently working on, but I can try to help as much as possible here.