putStream_Request method

StreamedRequest putStream_Request(
  1. Stream<List<int>> localData,
  2. PathUri path, {
  3. required int contentLength,
  4. DateTime? lastModified,
  5. DateTime? created,
  6. void onProgress(
    1. double progress
    )?,
})

Request to put a new file at path with localData as content.

See:

  • putStream for a complete operation executing this request.

Implementation

http.StreamedRequest putStream_Request(
  Stream<List<int>> localData,
  PathUri path, {
  required int contentLength,
  DateTime? lastModified,
  DateTime? created,
  void Function(double progress)? onProgress,
}) {
  final request = http.StreamedRequest('PUT', _constructUri(path));

  _addBaseHeaders(request);
  _addUploadHeaders(
    request,
    lastModified: lastModified,
    created: created,
    contentLength: contentLength,
  );

  if (onProgress != null) {
    var uploaded = 0;

    unawaited(
      localData.map((chunk) {
        uploaded += chunk.length;
        onProgress.call(uploaded / contentLength);
        return chunk;
      }).pipe(request.sink),
    );
  } else {
    unawaited(
      localData.pipe(request.sink),
    );
  }

  return request;
}