781flyingdutchman / background_downloader

Flutter plugin for file downloads and uploads
Other
165 stars 76 forks source link

Start download from the beginning #334

Closed nahid-urelaa closed 4 months ago

nahid-urelaa commented 5 months ago

for example :

My file size is 100 MB. When I start the download, it proceeds to 50% completion. However, if my network connection is interrupted at that point, the download restarts from the beginning once the network is restored. Ideally, the download should resume from where it left off.

this is my code :

void downloadConfig() {

FileDownloader().configure(
  globalConfig: [
    (Config.requestTimeout, const Duration(seconds: 100)),
  ],
  androidConfig: [(Config.runInForegroundIfFileLargerThan, 200)],
  iOSConfig: [
    (Config.localize, {'Cancel': 'StopIt'}),
  ],
);

}

void downloadNotificationSetup() {

FileDownloader()
    .configureNotificationForGroup(
      FileDownloader.defaultGroup,
      running: const TaskNotification('Download running',
          'Video - {progress} - speed {networkSpeed} and {timeRemaining} remaining'),
      complete:
          const TaskNotification('Download complete', 'Download complete'),
      error: const TaskNotification('Download error', 'Download failed'),
      paused: const TaskNotification(
          'Download pause', 'Paused with metadata {metadata}'),
      progressBar: true,
      tapOpensFile: false,
    )
    .configureNotification(
      complete: const TaskNotification(
          'Download {filename}', 'Download complete'),
      tapOpensFile: false,
      progressBar: true,
    );

}

Future downloadSingleVideo( {required String url, required String fileName, required int fileSize}) async { double fileSizeInMB = fileSize / (1024 * 1024); try {

  final task = DownloadTask(
      url: url,
      filename: "$fileName.mp4",
      baseDirectory: BaseDirectory.root,
      directory: controller.haveSDCard
          ? controller.sdCardPath
          : controller.localStoragePath,
      updates: Updates.statusAndProgress,
      allowPause: true,
      retries: 5,
      taskId: fileName);

  final successfullyEnqueued = await FileDownloader().enqueue(
    task,
  );
  if (successfullyEnqueued) {
    controller.onGoingAllDownloadingFileSize += fileSizeInMB;
    controller.taskMapping[task.taskId] =
        VideoFile(fileName: fileName, fileSize: fileSizeInMB);
  } else {
    showMassage("Download failed to start.", isSuccess: false);
  }
} catch (err) {
  showApiErrorMessage(err);
}

}

Can you please help me

781flyingdutchman commented 5 months ago

Thanks for reaching out. The download will resume from where it was interrupted only if the server allows for that, and a few other conditions ,and it sounds like that may not be the case. I don't think there's anything I can help with, sorry