Skip to content

Rule Engine

Robin Rodricks edited this page Jul 21, 2026 · 7 revisions

API

Tip: For detailed documentation refer to the IntelliSense tips that appear when you call a given API method.

These Polycloud API methods currently support the rule engine.

  • IStore.UploadDirectory()

  • IStore.DownloadDirectory()

How do rules work?

Rules allow you to declaratively specify which files and folders should be copied and which should be skipped. There are rules that let you filter on file extension (eg: upload only PDF files) or folder name (eg: skip folders called "node_modules") and various other parameters.

Only files that pass all the rules are copied from the source to the target.

What kinds of rules are supported?

First import the FluentStorage.Rules NS and then use any of these rules:

Rule Class Parameters Description
ExtensionRule extensions Only transfer objects of a certain extension, or blacklist files of a certain extension. Only works if the object has an extension in its path.
ObjectNameRule names Only transfer objects of a certain name, or blacklist files of a certain name
DirectoryNameRule names Only transfer folders of a certain name, or blacklist folders of a certain name
FullPathRule paths Only transfer objects that contain the given path(s), or blacklist objects that contain the given path(s)
ObjectNameRegexRule regexPatterns Only transfer objects whose names match the given regular expression(s), or blacklist files that match
DirectoryNameRegexRule regexPatterns Only transfer folders whose names match the given regular expression(s), or blacklist folders that match
FullPathRule regexPatterns Only transfer objects whose full paths match the given regular expression(s), or blacklist files that match

How do I use rules to only download PDF files within the attachments subfolder?

Declare the rules and then call DownloadDirectory or UploadDirectory with those rules:

var rules = new List<StorageRule>{
   new ExtensionRule(true, new List<string>{ "pdf" }),  // only allow PDF files
   new DirectoryNameRule(true, "attachments ")          // only allow anything in the "attachments" folder
};

await client.DownloadDirectory(@"/user/home/", @"C:\homedir\", StorageExistsMode.Skip, null, rules);

How do I use rules to skip large and unwanted directories?

Declare the rules and then call DownloadDirectory or UploadDirectory with those rules:

// this uses the pre-defined blacklist that skips directories named `.git`, `.svn`, `node_modules` etc
var rules = new List<StorageRule>{
   new DirectoryNameRule(false, DirectoryNameRule.CommonBlacklistedFolders),
};

await client.DownloadDirectory(@"/user/home/attachments", @"C:\attachments\", StorageExistsMode.Skip, null, rules);

Clone this wiki locally