addFile method
- dynamic file
Adds a file to IPFS using chunked streaming.
file must be a Stream<List<int>> of the file's bytes — on the
web this is typically file.stream() from a dart:html/
package:web File (or a FileReader result); on native,
file.openRead(). The stream is consumed via addStream, so the
returned CID matches IPFSNode.addFile for identical bytes.
Throws UnsupportedError for any other input type: this class
cannot import dart:html, so browser File objects cannot be read
here — obtain a byte stream first and pass that (or call addStream
directly). Declared dynamic precisely so this library compiles
without the web-only File type.
Implementation
Future<CID> addFile(dynamic file) {
if (file is Stream<List<int>>) {
return addStream(file);
}
throw UnsupportedError(
'IPFSWebNode.addFile requires a Stream<List<int>> of file bytes: '
'browser File objects cannot be read without dart:html, which this '
'library does not import — pass file.stream() (web) or '
'file.openRead() (native), or call addStream() directly',
);
}