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

Cancelling file(Or stop downloading option) #208

Open
2 tasks done
shyamkawale opened this issue Aug 5, 2020 · 8 comments
Open
2 tasks done

Cancelling file(Or stop downloading option) #208

shyamkawale opened this issue Aug 5, 2020 · 8 comments
Labels
type: enhancement New feature or request

Comments

@shyamkawale
Copy link

shyamkawale commented Aug 5, 2020

🚀 Feature Requests

Describe the feature

Like if i am storing video file in cache and in between i want to cancel the ongoing download.

I tried doing this with remove method but in background downloading was still going no matter what i do ,file gets downloaded fully in background..

If there is solution available already then pls tell me how to do!!!!

Platforms affected (mark all that apply)

  • 📱 iOS
  • 🤖 Android
@renefloor
Copy link
Contributor

Such a feature is not implemented yet.

@renefloor renefloor added the type: enhancement New feature or request label Oct 8, 2020
@aytunch
Copy link

aytunch commented Jan 10, 2021

@shyamkawale I have the exact same need. I have a list of videos and if the user browses the list quickly, I end up with 10s of started downloads and no way to stop the past ones
@renefloor are we planning on implementing this feature?
it would be very beneficial for performance.

@renefloor
Copy link
Contributor

The http library is currently implementing such a feature and when they do it won't be difficult to use it in this package.
See dart-lang/http#424

@bohdan1krokhmaliuk
Copy link

bohdan1krokhmaliuk commented Mar 1, 2021

@renefloor

Isn't it possible to stop download process if you use IOStreamedResponse from 'package:http/io_client.dart' instead of ordinary StreamedResponse. In case, we need to cancel file download, we can simply make final socket = await _response.detachSocket() and socket.destroy() after.

/// Basic implementation of a [FileServiceResponse] for http requests.
class HttpGetResponse implements FileServiceResponse {
  HttpGetResponse(this._response);

  final DateTime _receivedTime = clock.now();

  final http.StreamedResponse _response;

  @override
  int get statusCode => _response.statusCode;

  bool _hasHeader(String name) {
    return _response.headers.containsKey(name);
  }

  String _header(String name) {
    return _response.headers[name];
  }

  @override
  Stream<List<int>> get content => _response.stream;

  @override
  int get contentLength => _response.contentLength;

  @override
  DateTime get validTill {
    // Without a cache-control header we keep the file for a week
    var ageDuration = const Duration(days: 7);
    if (_hasHeader(HttpHeaders.cacheControlHeader)) {
      final controlSettings =
          _header(HttpHeaders.cacheControlHeader).split(',');
      for (final setting in controlSettings) {
        final sanitizedSetting = setting.trim().toLowerCase();
        if (sanitizedSetting == 'no-cache') {
          ageDuration = const Duration();
        }
        if (sanitizedSetting.startsWith('max-age=')) {
          var validSeconds = int.tryParse(sanitizedSetting.split('=')[1]) ?? 0;
          if (validSeconds > 0) {
            ageDuration = Duration(seconds: validSeconds);
          }
        }
      }
    }

    return _receivedTime.add(ageDuration);
  }

  @override
  String get eTag => _hasHeader(HttpHeaders.etagHeader)
      ? _header(HttpHeaders.etagHeader)
      : null;

  @override
  String get fileExtension {
    var fileExtension = '';
    if (_hasHeader(HttpHeaders.contentTypeHeader)) {
      var contentType =
          ContentType.parse(_header(HttpHeaders.contentTypeHeader));
      fileExtension = contentType.fileExtension ?? '';
    }
    return fileExtension;
  }
}

@sahhill
Copy link

sahhill commented Apr 5, 2022

Hi @renefloor,

is this issue on the list, if yes, when will it be fixed?

@renefloor
Copy link
Contributor

@sahhill this is definitely still on the list. I'm currently in a busy period personally, so don't expect new features soon. After the summer I'll have more time for open source work again.

@fingerart
Copy link

how's the progress?

@atsince
Copy link

atsince commented Nov 8, 2024

how's the progress? when will it be fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

7 participants