putObject function
Uploads bytes to path, answering with the stored object's metadata.
Implementation
Future<StorageMetadata> putObject(
String path,
Uint8List bytes, {
String? contentType,
}) async {
final p = path.toNativeUtf8();
final type = (contentType ?? '').toNativeUtf8();
// Copied into native memory for the call. The native side copies again for
// the duration of the upload, because PutBytes does not take ownership and
// completes long after this returns.
final buf = calloc<Uint8>(bytes.isEmpty ? 1 : bytes.length);
buf.asTypedList(bytes.length).setAll(0, bytes);
try {
final payload = await _awaitBuffer(
(port) => fdbStoragePut(p.cast(), buf, bytes.length, type.cast(), port),
'put $path',
);
return _decodeMetadata(payload);
} finally {
calloc
..free(p)
..free(type)
..free(buf);
}
}