putBlob method
Put Blob.
body
and bodyBytes
are mutually exclusive and mandatory.
Implementation
Future<void> putBlob(String path,
{String? body,
Uint8List? bodyBytes,
required String contentType,
BlobType type = BlobType.BlockBlob}) async {
assert((bodyBytes == null) ^ (body == null));
var request = http.Request('PUT', uri(path: path));
request.headers['x-ms-blob-type'] =
type.toString() == 'BlobType.AppendBlob' ? 'AppendBlob' : 'BlockBlob';
request.headers['content-type'] = contentType;
if (type == BlobType.BlockBlob) {
if (bodyBytes != null) {
request.bodyBytes = bodyBytes;
} else if (body != null) {
request.body = body;
}
} else {
request.body = '';
}
_sign(request);
var res = await request.send();
if (res.statusCode == 201) {
await res.stream.drain();
if (type == BlobType.AppendBlob && (body != null || bodyBytes != null)) {
await appendBlock(path, body: body, bodyBytes: bodyBytes);
}
return;
}
var message = await res.stream.bytesToString();
throw AzureStorageException(message, res.statusCode, res.headers);
}