react-native-blob-util icon indicating copy to clipboard operation
react-native-blob-util copied to clipboard

Android: received progress is always 0 when DownloadManager is false

Open eduardo-santos-tribia opened this issue 1 year ago • 4 comments

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

eduardo-santos-tribia avatar Mar 17 '23 14:03 eduardo-santos-tribia

did you find any solution for this @eduardo-santos-tribia ?

crackhack8266 avatar Dec 04 '23 07:12 crackhack8266

No. I had to set useDownloadManager to true.

eduardo-santos-tribia avatar Dec 05 '23 10:12 eduardo-santos-tribia

@eduardo-santos-tribia I set useDownloadManager to true and still not working. Any suggestions?

CarlosAlbertoTI avatar Jan 09 '24 13:01 CarlosAlbertoTI

@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.

eduardo-santos-tribia avatar Jan 11 '24 11:01 eduardo-santos-tribia