putObject method

Future<String> putObject(
  1. String bucket,
  2. String object,
  3. Stream<Uint8List> data, {
  4. int? size,
  5. int? chunkSize,
  6. Map<String, String>? metadata,
  7. void onProgress(
    1. int
    )?,
})

Uploads the object. Returns the ETag of the uploaded object.

Implementation

Future<String> putObject(
  String bucket,
  String object,
  Stream<Uint8List> data, {
  int? size,
  int? chunkSize,
  Map<String, String>? metadata,
  void Function(int)? onProgress,
}) async {
  MinioInvalidBucketNameError.check(bucket);
  MinioInvalidObjectNameError.check(object);

  if (size != null && size < 0) {
    throw MinioInvalidArgumentError('invalid size value: $size');
  }

  if (chunkSize != null && chunkSize < 5 * 1024 * 1024) {
    throw MinioInvalidArgumentError('Minimum chunk size is 5MB');
  }

  metadata = prependXAMZMeta(metadata ?? <String, String>{});

  final partSize = chunkSize ?? _calculatePartSize(size ?? maxObjectSize);

  final uploader = MinioUploader(
    this,
    _client,
    bucket,
    object,
    partSize,
    metadata,
    onProgress,
  );
  final chunker = MinChunkSize(partSize);
  final etag = await data.transform(chunker).pipe(uploader);
  return etag.toString();
}