Table of Contents

Interface IUploadRule

Namespace
HeroKit.FileTypes
Assembly
HeroKit.FileTypes.dll

An extra check for uploads, run after the built-in checks. Add instances to Rules.

public interface IUploadRule
Extension Methods

Examples

sealed class NoEmptyPdfRule : IUploadRule
{
    public string? Validate(ReadOnlySpan<byte> header, string fileName, FileType? detectedType) =>
        detectedType == FileTypes.Pdf && header.Length < 100 ? "The PDF is too small." : null;
}

Methods

Validate(ReadOnlySpan<byte>, string, FileType?)

Checks an upload.

string? Validate(ReadOnlySpan<byte> header, string fileName, FileType? detectedType)

Parameters

header ReadOnlySpan<byte>

The first bytes of the file (the whole file when it is shorter than HeaderSize).

fileName string

The file name as uploaded.

detectedType FileType

The type detected from the content, or null.

Returns

string

A message that explains why the upload is rejected, or null to accept it.