react-native-blob-util
react-native-blob-util copied to clipboard
Android: received progress is always 0 when DownloadManager is false
Hi, I've created an issue related to the use of DownloadManager, so because of that I'm trying to not use the DownloadManager. It's working almost properly: Download is ok, cancel is ok, but the received progress value is always 0 when I'm not using the DownloadManager.
Is the progress for Android directly related to the use of DownloadManager? Can I have the progress with DownloadManager = false?
This is my react-native-blob-util implementation:
const configOptions = ...defaultFetchBlobOptions,
fileCache: true,
indicator: true,
overwrite: true,
addAndroidDownloads: {
useDownloadManager: false,
notification: true,
mediaScannable: true,
path: path,
title: contentName,
description: contentDescription,
mime: mimeType,
},
}
const fetchBlobTaskRef = useRef<StatefulPromise<FetchBlobResponse>>()
const cancelFetch = () => {
fetchBlobTaskRef?.current?.cancel()
}
const handleFetch = async () => {
fetchBlobTaskRef.current = ReactNativeBlobUtil.config(
configOptions,
).fetch('GET', url)
fetchBlobTaskRef.current
.progress((received, total) => {
const currentProgress = received / total
console.log({received}) // logs "received": "0" every time.
})
.then(async res => {
const resStatus = res && res.info ? res.info().status : 'Unknow'
if (resStatus === ApiHttpStatusEnum.OK) {
if (IS_ANDROID) {
await handleAndroidDownload(res, contentName, mimeType)
}
} else {
log(`Something went wrong downloading ${contentName}, status ${resStatus}`)
}
})
.catch(error => {
console.log(error)
})
}
More info:
-
RN: 0.71.3
-
BlobUtil: ^0.17.2
did you find any solution for this @eduardo-santos-tribia ?
No. I had to set useDownloadManager
to true
.
@eduardo-santos-tribia I set useDownloadManager
to true
and still not working. Any suggestions?
@CarlosAlbertoTI check this other issue where I explain also how I solved the issue setting the useDownloadManager to true. If you still have errors, please share more info with us what exactly is the error and what are the settings you're using.