formaui-net.Framework.Resources
1.0.0-preview.27
Prefix Reserved
dotnet add package formaui-net.Framework.Resources --version 1.0.0-preview.27
NuGet\Install-Package formaui-net.Framework.Resources -Version 1.0.0-preview.27
<PackageReference Include="formaui-net.Framework.Resources" Version="1.0.0-preview.27" />
<PackageVersion Include="formaui-net.Framework.Resources" Version="1.0.0-preview.27" />
<PackageReference Include="formaui-net.Framework.Resources" />
paket add formaui-net.Framework.Resources --version 1.0.0-preview.27
#r "nuget: formaui-net.Framework.Resources, 1.0.0-preview.27"
#:package formaui-net.Framework.Resources@1.0.0-preview.27
#addin nuget:?package=formaui-net.Framework.Resources&version=1.0.0-preview.27&prerelease
#tool nuget:?package=formaui-net.Framework.Resources&version=1.0.0-preview.27&prerelease
Forma.Framework.Resources
The contracts that connect Forma.Blazor's file components to wherever an application keeps its
files. A stored file is described as a ResourceInfo, and the host implements how a file is
stored (IFileStore), how an address resolves to a resource (IResourceProvider) and how the
bytes behind an address are opened (IResourceContentReader). The package depends only on .NET,
so the implementations can live in any class library.
Install
dotnet add package formaui-net.Framework.Resources --prerelease
Resources
ResourceInfo names a resource by its Source, a URL or a path, and carries its Name, the last
segment of the address unless set, and an optional Size, CreatedAt and ModifiedAt. A derived
record says what kind of resource it is:
| Record | Adds |
|---|---|
FolderResourceInfo |
Parent, the folder it sits in, and Count, the resources it holds. |
FileResourceInfo |
ContentType and Extension. |
ImageResourceInfo |
Width and Height. |
VideoResourceInfo |
Width, Height and Duration. |
AudioResourceInfo |
Duration. |
DocumentResourceInfo |
Count, its pages. |
MarkupResourceInfo |
Html, a document converted to sanitized markup. |
ArchiveResourceInfo |
Count, the resources it holds. |
IVisualResource exposes Width and Height, and ITimedResource exposes Duration, across
the records that have them. Every optional property is set in an object initializer:
using Forma.Framework.Resources;
var cover = new ImageResourceInfo("/media/cover.jpg")
{
ContentType = "image/jpeg",
Size = 184_320,
Width = 1600,
Height = 900,
};
Contracts
| Member | What it does |
|---|---|
IFileStore.SaveAsync(content, cancellationToken) |
Stores a FileContent and returns a FileSaveResult, the ResourceInfo it became or the store's FileRefusal of it. FormaFileUploader saves each file through it. |
IFileStore.DeleteAsync(resource, cancellationToken) |
Removes a resource the store saved, and returns whether it did. |
IResourceProvider.GetResourceAsync(source, cancellationToken) |
The resource an address names, or null for an address another provider handles. |
IResourceContentReader.OpenAsync(source, cancellationToken) |
A stream over the bytes behind an address, which the caller disposes, or null when the reader has no such address. |
FileContent carries a file's Name, ContentType, Size and open Stream; the caller owns the
stream and disposes it after SaveAsync returns.
A store answers FileSaveResult.Saved(resource) for a file it kept and
FileSaveResult.Refused(refusal) for one it turns away for a reason the reader can act on, and
throws only for a failure. A FileRefusal carries its Reason and the Limit the file went past:
FileRefusalReason |
The file | Limit |
|---|---|---|
DisallowedType |
Is of a type the store doesn't take. | None. |
TooLarge |
Holds more bytes than the store takes in one file. | The most bytes. |
TooWide |
Is an image wider than the store takes. | The most pixels across. |
TooTall |
Is an image taller than the store takes. | The most pixels down. |
Other |
Is refused for a reason of the store's own. | None. |
FormaFileUploader shows a refused file as refused, beneath it a sentence in the reader's language
that names the limit, and a failed file as failed. A store enforces its own limits, whatever a
picker checked before it.
A refusal's Message is the store's own words for it, a LocalizableText the uploader shows in place
of its own sentence, localized in the reader's language as it's shown. A store refusing for a reason
of its own, such as the reader's access to a folder taken away while they chose the files, answers
with Other and its words for it:
return FileSaveResult.Refused(new FileRefusal(FileRefusalReason.Other)
{
Message = LocalizableText.For<UploadFolderStore>("You can no longer add files to this folder."),
});
FormaFileViewer asks each registered IResourceProvider in registration order, and the first
resource returned decides how the address is shown. BrowserResourceProvider, which recognizes
the images, audio, video, PDF and text a browser renders itself, answers last without being
registered. A provider that returns a MarkupResourceInfo sanitizes its Html, since the viewer
renders it as markup.
Register
The host implements the store and the reader over its own storage and registers them, with any providers it adds:
using Forma.Framework.Resources;
using Forma.Framework.Resources.Markdown;
var uploads = Path.Combine(builder.Environment.ContentRootPath, "uploads");
builder.Services.AddScoped<IFileStore>(_ => new UploadFolderStore(uploads));
builder.Services.AddScoped<IResourceContentReader>(_ => new UploadFolderReader(uploads));
builder.Services.AddScoped<IResourceProvider, MarkdownResourceProvider>();
formaui-net.AddOns.Resources.Markdown
and formaui-net.AddOns.Resources.Office
provide MarkdownResourceProvider and OfficeResourceProvider, which convert documents to a
MarkupResourceInfo through the host's IResourceContentReader.
A store and a reader over a folder whose files are served under /uploads/, the store taking
no file over 10 MB:
using Forma.Framework.Resources;
public sealed class UploadFolderStore(string folder) : IFileStore
{
private const long MaxFileBytes = 10 * 1024 * 1024;
public async ValueTask<FileSaveResult> SaveAsync(FileContent content, CancellationToken cancellationToken)
{
if (content.Size > MaxFileBytes)
{
return FileSaveResult.Refused(new FileRefusal(FileRefusalReason.TooLarge, MaxFileBytes));
}
await using var destination = File.Create(Path.Combine(folder, content.Name));
await content.Stream.CopyToAsync(destination, cancellationToken);
return FileSaveResult.Saved(new FileResourceInfo($"/uploads/{content.Name}")
{
ContentType = content.ContentType,
Size = content.Size,
});
}
public ValueTask<bool> DeleteAsync(ResourceInfo resource, CancellationToken cancellationToken)
{
var path = Path.Combine(folder, resource.Name);
if (!File.Exists(path))
{
return ValueTask.FromResult(false);
}
File.Delete(path);
return ValueTask.FromResult(true);
}
}
public sealed class UploadFolderReader(string folder) : IResourceContentReader
{
public ValueTask<Stream?> OpenAsync(string source, CancellationToken cancellationToken)
{
var path = Path.Combine(folder, new ResourceInfo(source).Name);
return ValueTask.FromResult<Stream?>(File.Exists(path) ? File.OpenRead(path) : null);
}
}
Formatting measurements
ResourceFormatter writes measurements in the culture it is given: FromByteCount as B, KB,
MB, GB or TB, FromDuration as milliseconds, seconds, m:ss or h:mm:ss, and
FromTransferRate as a byte count per second, such as 1.5 MB/s in English and 1,5 MB/s in German.
The FormatSize(culture) extension method, in Forma.Framework.Resources.Extensions, writes a
resource's Size the same way, or null when the size is unknown.
License
Apache License 2.0, under the repository's LICENSE.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- formaui-net.Framework.Localization (= 1.0.0-preview.27)
NuGet packages (11)
Showing the top 5 NuGet packages that depend on formaui-net.Framework.Resources:
| Package | Downloads |
|---|---|
|
formaui-net.Framework.Files
The types Forma.Blazor's file components report and track: a file a picker declined and why, a file an uploader could not store and the error that stopped it, a file a store refused and why, and the progress of each file in an upload. |
|
|
formaui-net.Framework.Share
The share contracts: the item a share menu acts on, the targets an item can be shared to, and the sources a host answers a user's credentials through. |
|
|
formaui-net.Blazor
A Blazor component library for .NET 11: form inputs and pickers, dialogs, popovers and toasts, toolbars and menus, tabs and layout, file pickers, uploaders and viewers, icons, emoji and windows. |
|
|
formaui-net.Framework.Composer.Extensibility
The contracts a FormaComposer plugin is written against: what a plugin contributes, what it reads of the composer while it runs, and what it can ask the composer to do. |
|
|
formaui-net.Framework.Catalog
The model of a browsable collection of items and folders: the item and folder contracts, the provider that answers one slice of them at a time, the requests a surface hands back when the reader renames, deletes or moves something, and the ceilings a collection keeps. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-preview.27 | 73 | 12/3/2026 |
| 1.0.0-preview.26 | 82 | 12/3/2026 |
| 1.0.0-preview.25 | 92 | 12/2/2026 |
| 1.0.0-preview.24 | 115 | 12/1/2026 |
| 1.0.0-preview.23 | 167 | 11/30/2026 |
| 1.0.0-preview.22 | 173 | 11/30/2026 |
| 1.0.0-preview.21 | 176 | 11/29/2026 |
| 1.0.0-preview.20 | 174 | 11/26/2026 |
| 1.0.0-preview.19 | 178 | 11/26/2026 |
| 1.0.0-preview.18 | 169 | 11/26/2026 |
| 1.0.0-preview.17 | 157 | 11/26/2026 |
| 1.0.0-preview.16 | 153 | 11/24/2026 |
| 1.0.0-preview.15 | 156 | 11/23/2026 |
| 1.0.0-preview.14 | 153 | 11/23/2026 |
| 1.0.0-preview.13 | 153 | 11/21/2026 |
| 1.0.0-preview.12 | 150 | 11/20/2026 |
| 1.0.0-preview.11 | 146 | 11/18/2026 |
| 1.0.0-preview.10 | 152 | 11/17/2026 |
| 1.0.0-preview.9 | 186 | 11/17/2026 |
| 1.0.0-preview.8 | 154 | 11/17/2026 |
What this release changed is in Forma's changelog: https://github.com/FormaUI/Forma/blob/v1.0.0-preview.27/CHANGELOG.md