File and Form Uploads
Parse multipart and form submissions with streaming storage and limits.
Chapters
- Basic multipart/form-data upload
- Multiple files (same field name)
- application/x-www-form-urlencoded forms
- multipart/mixed ordered parts
- Nested multipart/mixed
- Request-level compression
- Part-level compression
- OpenAPI: basic multipart upload
- OpenAPI: multiple files
- OpenAPI: urlencoded forms
- OpenAPI: multipart/mixed
- OpenAPI: nested multipart
- OpenAPI: request-level compression
- OpenAPI: part-level compression
- OpenAPI: file hash upload
- Form rules: file hash upload
Gotchas
Add-KrFormRouteinjects$FormPayloaddirectly into the runspace (you already have$Context).- Content types:
Add-KrFormRouteacceptsmultipart/form-databy default. The urlencoded andmultipart/mixedchapters explicitly opt in viaKrFormOptions.AllowedRequestContentTypes. - For request-level compression examples, make sure you send a real
byte[]body withContent-Encoding: gzip(avoid returning an enumeratedObject[]of bytes from helper functions).
Multipart rules (KrPartRule)
These examples configure upload validation rules via KrFormOptions.Rules.
- Rules match by part name (the
name="..."value from theContent-Dispositionheader). - For
multipart/form-data, this is usually present by default. - For ordered
multipart/mixed, you must include aContent-Dispositionheader with aname=for each part if you want rules to apply. - If a part has no
name, it can still be parsed (as ordered content), but no named rule can match it.
Common rule knobs used in this chapter:
Required: Rejects the request if a named part is missing.AllowMultiple: Rejects multiple occurrences when set to$false.AllowedContentTypes/AllowedExtensions: Rejects mismatched uploads.MaxBytes: Rejects oversized parts.
Prerequisites
- PowerShell 7.4+
- .NET runtime per repo
global.json