Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-downloading a file appends to itself instead of overwriting #7

Open
flutternoob opened this issue Oct 21, 2021 · 0 comments
Open

Comments

@flutternoob
Copy link

Hi, when I re-download a file, the file appends to itself instead of overwriting it. For example, if I have an already downloaded file that is 10MB in size and I redownload the file, its size will be 20 MB instead of the same 10 MB. I could use a check to see if the file exists, but the file should still be overwritten instead of appended to itself. Also, if the internet connection fails, the incomplete download does not get deleted.

Here's my code:

if (await InternetConnectionChecker().hasConnection) {
      final downloaderUtils = DownloaderUtils(
        progressCallback: (current, total) async {
          final int progress = ((current / total) * 100).toInt();
          if (progress == 100) {
            await flutterLocalNotificationsPlugin.cancel(123);
          }
        },
        file: File(filePath),
        progress: ProgressImplementation(),
        // ignore: avoid_print
        onDone: () {
          SnackBar downloadFinished = SnackBar(
            content: Text("Finished downloading $itemName"),
            behavior: SnackBarBehavior.floating,
            duration: Duration(seconds: 3),
          );
          ScaffoldMessenger.of(context).showSnackBar(downloadFinished);
        },
        deleteOnCancel: true,
      );
      final core = await Flowder.download(fileUrl, downloaderUtils);

      await flutterLocalNotificationsPlugin.show(123, "Downloading file $itemName, \nplease wait.", "", notificationDetails);
    } else {
      await flutterLocalNotificationsPlugin.cancel(123);
      SnackBar downloadFailed = SnackBar(
        content: Text("Download of $itemName failed. Please try again"),
        behavior: SnackBarBehavior.floating,
        duration: Duration(seconds: 3),
      );
      ScaffoldMessenger.of(context).showSnackBar(downloadFailed);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant