putBlobStreaming method

Future<Map<String, dynamic>> putBlobStreaming({
  1. required File file,
  2. String? encodingType,
  3. int? epochs,
  4. bool? deletable,
  5. String? sendObjectTo,
  6. String? jwtToken,
})

Streams file contents to the publisher without loading everything into memory.

Implementation

Future<Map<String, dynamic>> putBlobStreaming({
  required File file,
  String? encodingType,
  int? epochs,
  bool? deletable,
  String? sendObjectTo,
  String? jwtToken,
}) async {
  if (!await file.exists()) {
    throw FileSystemException('File does not exist', file.path);
  }

  logInfo('Streaming upload for file ${file.path}');
  final uri = _publisherUri(
    'v1/blobs',
    queryParameters: _buildQueryParameters(
      epochs: epochs,
      deletable: deletable,
      sendObjectTo: sendObjectTo,
    ),
  );

  final response = await _executor.send(
    method: 'PUT',
    uri: uri,
    headers: _buildHeaders(jwtToken: jwtToken),
    bodyStream: file.openRead(),
  );

  final result = await _parseJsonResponse(
    response,
    context: 'Error uploading blob',
  );
  logInfo('Streaming upload completed with status ${response.statusCode}');
  return result;
}