Skip to content

Cancel Download function not working #370

Open
@TirumalReddy

Description

@TirumalReddy

Description:
The cancel() method in react-native-blob-util is not functioning as expected. When attempting to cancel an ongoing download, the download continues instead of being halted.

Steps to Reproduce:

Start a download using react-native-blob-util.
Attempt to cancel the download using the cancel() method.
Observe that the download continues despite the cancellation attempt.

Expected Behavior:
The download should be halted immediately upon calling the cancel() method.

Actual Behavior:
The download continues even after calling the cancel() method.

Environment:

Library Version: 0.18.6
React Native Version: 0.71.7
Platform: Android & IOS

Code Example:

       let DownloadDir = "Storage/to/Path"
        let fileName = Name + extension;
        let filePath = DownloadDir + fileName;
        let folderName = DownloadDir + Name;
        
        let options = {
            fileCache: true,
            addAndroidDownloads: {
                useDownloadManager: true,
                notification: false,
                path: filePath,
                description: "downloading...",
            },
            path: filePath,
        };


       const task = config(options)
            .fetch("GET", FILE_URL)
            .progress((received, total) => {
                const progress = Math.floor((received / total) * 100);
            })
            .then((res) => {
                console.log("res)
            })
            .catch((error) => {
                if (fs.exists(folderName)) {
                    fs.unlink(folderName);
                }
            });


        task.cancel((err) => {
          if (err) {
            console.error('Failed to cancel download:', err);
          } else {
            console.log('Download cancelled successfully');
          }
      });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions