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. String? checksum,
  7. void onProgress(
    1. double progress
    )?,
})

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

contentLength sets the length of the localData that is uploaded. lastModified sets the date when the file was last modified on the server. created sets the date when the file was created on the server. checksum has to follow checksumPattern. It will not be validated by the server. onProgress can be used to watch the upload progress. Possible values range from 0.0 to 1.0.

See:

Implementation

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

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

  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;
}