FilePlace
The places an application keeps files, each a folder of its own.
A place names a kind of file, never a path. Your application says one root, once — in
CkSettings.DefaultFileRoot, in appsettings.json or in a variable
(Your file places, set once; step by step on
Setting up your file places) — and each
place is the subfolder named after it, Images, Audio, Documents, made when first
written to; a place that lives elsewhere gets a folder of its own. Every file operation on
CkFile takes a place and a relative path, never a full one. With no
root and no folder said, a place refuses every operation, so as shipped nothing can touch
a disk. Each place also says what it takes: the extensions and the most bytes a file may
have, with the library's own defaults when you set none.
There is no Root on purpose: a file is always inside a named folder, never beside the
application or the site, so a path that climbs — ../web.config — is never in bounds.
Members
| Member | Meaning | Takes by default |
|---|---|---|
Uploads |
Files as they arrive, before they are checked and filed. | every extension below |
Temporary |
Scratch files, safe to clear at any time. | every extension below |
Images |
Pictures. | jpg, jpeg, png, gif, webp, bmp, tif, tiff, heic, avif |
Videos |
Video files. | mp4, mov, webm, mkv, avi |
Audio |
Audio files. | mp3, wav, ogg, m4a, flac |
Media |
Pictures, video and audio kept together, where an application has one media folder rather than three. | the three lists above |
Documents |
Documents: PDFs, office files, scans. | pdf, doc, docx, xls, xlsx, ppt, pptx, odt, ods, odp, rtf, txt, csv |
Imports |
Data received to be read in: spreadsheets, CSV, JSON and XML feeds. | csv, xlsx, xls, json, xml, txt |
Exports |
Files the application makes for people to download: reports, invoices, extracts. | pdf, csv, xlsx, docx, json, zip |
Archives |
Archives: zip and its kin. | zip, 7z, rar, gz, tar |
Every place takes 2 MB (CkSettings.DefaultMaxFileBytes) until you say otherwise, and
none takes a blocked extension — a program, a script, a web page — however it is listed.
Where it is used
Every file operation on CkFile — Write, Read, ReadOrNull,
Copy, Move, Delete, Exists, Size, SizeOrNull, Files, FullPath, IsAllowed,
AllowedExtensions and MaxBytes — takes a place as its first parameter, Uploads unless said, and the three
settings methods CkSettings.FileRoot, FileExtensions and FileMaxBytes answer for one.
Quick look
using SafeCoder.CommonKit;
using SafeCoder.CommonKit.Enums;
CkFile.Write(FilePlace.Documents, "claim-18/scan.pdf", bytes); // -> true (a PDF, within the limit)
CkFile.Write(FilePlace.Videos, "clip.mp4", bytes); // -> false (no folder is set for Videos)
CkFile.AllowedExtensions(FilePlace.Images); // -> ["jpg", "jpeg", "png", ...]
CkFile.MaxBytes(FilePlace.Images); // -> 2097152 as shipped