putStream_Request method
BaseRequest
putStream_Request(})
Request to put a new file at path
with localData
as content.
Setting contentLength
is important because some web servers will consider the file to be empty otherwise.
It will be required in the next major release.
See:
- putStream for a complete operation executing this request.
Implementation
http.BaseRequest putStream_Request(
Stream<List<int>> localData,
PathUri path, {
DateTime? lastModified,
DateTime? created,
int? contentLength,
void Function(double progress)? onProgress,
}) {
final request = http.StreamedRequest('PUT', _constructUri(path));
_addBaseHeaders(request);
_addUploadHeaders(
request,
lastModified: lastModified,
created: created,
contentLength: contentLength,
);
if (contentLength != null && 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;
}