addFile method

Future<String> addFile(
  1. Uint8List data
)

Adds a file to IPFS and returns its CID.

Implementation

Future<String> addFile(Uint8List data) async {
  try {
    // Create a new block from the file data
    final block = await Block.fromData(data);

    // Store the block in the datastore
    await _container.get<DatastoreHandler>().putBlock(block);

    // Notify listeners about the new content
    _newContentController.add(block.cid.toString());

    return block.cid.toString();
  } catch (e) {
    // print('Error adding file: $e');
    rethrow;
  }
}