addFile method

void addFile(
  1. AttachedFile file
)

Attaches a file to the message.

Files can be attached from local files or network URLs using various AttachedFile factory constructors. Each file attachment can include optional metadata such as spoiler flags, dimensions, and descriptions.

Example:

// From local file
builder.addFile(
  AttachedFile.fromFile(
    File('assets/document.pdf'),
    'document.pdf',
    description: 'Monthly report',
  ),
);

// From network URL
builder.addFile(
  await AttachedFile.fromNetwork(
    'https://example.com/image.png',
    'image.png',
    spoiler: true,
  ),
);

// From MediaItem
final mediaItem = MediaItem.fromFile(File('assets/logo.png'), 'logo.png');
builder.addFile(await AttachedFile.fromMediaItem(mediaItem));

See also:

Implementation

void addFile(AttachedFile file) {
  _components.add(file);
}