writeBlobAttributesTransaction method
Transaction
writeBlobAttributesTransaction({})
Build a complete write-blob-attributes transaction.
Reads existing attributes from the blob and applies the given
attributes map. If a value is null, the key is removed.
If non-null, the key is inserted or updated.
If the blob has no metadata yet, creates a new empty metadata object and attaches it first.
Mirrors the TS SDK's #writeBlobAttributesForRef().
Implementation
Transaction writeBlobAttributesTransaction({
required String blobObjectId,
required Map<String, String?> attributes,
Map<String, String>? existingAttributes,
Transaction? transaction,
}) {
final tx = transaction ?? Transaction();
final blobObj = tx.object(blobObjectId);
if (existingAttributes == null) {
// No metadata exists yet — create and attach.
final meta = createMetadata(tx: tx);
addMetadata(tx: tx, blobObject: blobObj, metadata: meta);
}
for (final entry in attributes.entries) {
if (entry.value == null) {
// Remove this key (only if it existed).
if (existingAttributes != null &&
existingAttributes.containsKey(entry.key)) {
removeMetadataPair(tx: tx, blobObject: blobObj, key: entry.key);
}
} else {
insertOrUpdateMetadataPair(
tx: tx,
blobObject: blobObj,
key: entry.key,
value: entry.value!,
);
}
}
return tx;
}