Skip to content

Files

Actions pass FileReference values instead of embedding file bytes in every input and output. A reference can be passed to another action or to a provider that accepts a download URL.

File references are temporary. See file retention and action memory before deciding where to keep long-lived content.

Add Blackbird.Applications.SDK.Extensions.FileManagement 1.1.0 alongside common SDK 2.17.0 in the Setup project. This file action counts lines from an input stream and creates a small report file.

Terminal window
dotnet add package Blackbird.Applications.SDK.Extensions.FileManagement --version 1.1.0
using System.Text;
using Blackbird.Applications.Sdk.Common;
using Blackbird.Applications.Sdk.Common.Actions;
using Blackbird.Applications.Sdk.Common.Files;
using Blackbird.Applications.Sdk.Common.Invocation;
using Blackbird.Applications.SDK.Extensions.FileManagement.Interfaces;
namespace Apps.FileExample;
[ActionList]
public class FileActions : BaseInvocable
{
private readonly IFileManagementClient _files;
public FileActions(InvocationContext context, IFileManagementClient files) : base(context)
=> _files = files;
[Action("Count file lines", Description = "Count lines in a UTF-8 text file and return a report")]
public async Task<LineReport> CountLines([ActionParameter] FileInput input)
{
using var stream = await _files.DownloadAsync(input.File);
using var reader = new StreamReader(stream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true);
var count = 0;
while (await reader.ReadLineAsync() is not null) count++;
using var report = new MemoryStream(Encoding.UTF8.GetBytes($"Line count: {count}"));
var file = await _files.UploadAsync(report, "text/plain", "line-report.txt");
return new LineReport { LineCount = count, File = file };
}
}
public class FileInput
{
[Display("File")]
public FileReference File { get; set; } = new();
}
public class LineReport
{
[Display("Line count")]
public int LineCount { get; set; }
[Display("Report file")]
public FileReference File { get; set; } = new();
}

The platform injects IFileManagementClient through the public constructor. DownloadAsync opens a reference as a stream; UploadAsync stores a stream and returns a reference for later steps.

When a provider exposes an authenticated download request, FileReference can be created from an HttpRequestMessage, filename, and content type. Blackbird retrieves the file. If you have already downloaded or transformed bytes, use IFileManagementClient.UploadAsync as above.

For upload actions, use DownloadAsync and stream the contents to the provider. When the provider accepts a download URL, use the reference’s URL according to its API contract.

A CMS download and upload pair must retain the information needed to reconstruct the content item. Use the content interchange libraries appropriate to your integration; reading an arbitrary file as plain text and rebuilding it loses that structure. The line-count example demonstrates file transport rather than a CMS conversion.

Stream larger files, dispose streams after use, and avoid reading a batch of files into memory at once. The provider’s file limits and Blackbird’s action memory limit both apply; references do not make those limits disappear.