Interface IAttachmentService
- Namespace
- Signal.Application.Abstractions
- Assembly
- Signal.Application.dll
Accesses attachments stored by the container (/v1/attachments).
public interface IAttachmentService
Methods
DeleteAsync(string, CancellationToken)
Deletes a stored attachment to free disk space in the container.
Task DeleteAsync(string attachmentId, CancellationToken cancellationToken = default)
Parameters
attachmentIdstringThe attachment id.
cancellationTokenCancellationTokenCancels the request.
Returns
- Task
A task that completes when the attachment was deleted.
DownloadAsync(string, CancellationToken)
Downloads an attachment completely into memory. Prefer OpenReadAsync(string, CancellationToken) for large files.
Task<byte[]> DownloadAsync(string attachmentId, CancellationToken cancellationToken = default)
Parameters
attachmentIdstringThe id from Id.
cancellationTokenCancellationTokenCancels the request.
Returns
ListAsync(CancellationToken)
Lists the ids of all stored attachments.
Task<IReadOnlyList<string>> ListAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenCancels the request.
Returns
- Task<IReadOnlyList<string>>
The attachment ids.
OpenReadAsync(string, CancellationToken)
Opens an attachment as a stream that reads directly from the HTTP response (GET /v1/attachments/{id}),
so large files never have to fit in memory. Dispose the result to release the connection.
Task<AttachmentDownload> OpenReadAsync(string attachmentId, CancellationToken cancellationToken = default)
Parameters
attachmentIdstringThe id from Id.
cancellationTokenCancellationTokenCancels opening the stream (reads take their own token).
Returns
- Task<AttachmentDownload>
The open download. The caller owns and must dispose it.
Examples
await using var download = await attachments.OpenReadAsync(attachment.Id, ct);
await using var file = File.Create(attachment.Filename ?? attachment.Id);
await download.Content.CopyToAsync(file, ct);
Remarks
The default implementation falls back to DownloadAsync(string, CancellationToken) and wraps the bytes in a MemoryStream, so existing IAttachmentService implementations keep working.
Exceptions
- SignalApiException
The attachment does not exist (404) or the API rejected the request.