ワンクリックで
horse-files-streams
Guide to handling file uploads (multipart), downloads, and stream lifetime management in the Horse framework.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Guide to handling file uploads (multipart), downloads, and stream lifetime management in the Horse framework.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Guidelines and workflows for developing and maintaining regular expressions and optional parameter routing features in the Horse framework.
Guidelines for registering, executing, and optimizing native high-precision telemetry hooks (AddOnTelemetry) in the Horse Web Framework.
Guidelines for instantiating and configuring independent Horse server instances (THorseInstance) running concurrently on different ports.
Guide for setting up thread-safe database connection pooling (FireDAC / UniDAC) in multithreaded Horse applications.
Guide for managing request-scoped contextual services and IoC (dependency injection) in Delphi and Lazarus.
Guide to using standard Horse middlewares (CORS, Jhonson, compression, basic-auth, logger) and pipeline registration order.
| name | horse-files-streams |
| description | Guide to handling file uploads (multipart), downloads, and stream lifetime management in the Horse framework. |
When clients upload files via multipart form data, you can retrieve the file as a stream or save it directly to the disk using the THorseCoreParamField helper from Req.ContentFields:
procedure UploadHandler(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
LFileField: THorseCoreParamField;
LStream: TStream;
begin
// 1. Get the file field
LFileField := Req.ContentFields.Field('file');
if not Assigned(LFileField) then
raise EHorseException.New
.Status(THTTPStatus.BadRequest)
.Error('No file was uploaded');
// 2. Save it directly to disk
LFileField.SaveToFile('C:\uploads\' + LFileField.FieldName);
// 3. Or access the raw TStream
LStream := LFileField.AsStream;
// Note: DO NOT free LStream if it is owned by the request lifecycle.
Res.Status(THTTPStatus.OK).Send('File uploaded successfully');
end;
To send files or custom data streams to the client, use Res.SendFile or Res.Download.
SendFile: Sends the file stream to the client (displays inline in the browser if supported).Download: Forces the browser to download the file with the specified filename.procedure DownloadHandler(Req: THorseRequest; Res: THorseResponse; Next: TProc);
var
LStream: TStream;
begin
LStream := TFileStream.Create('C:\data\report.pdf', fmOpenRead or fmShareDenyWrite);
// Sends the stream and instructs the client to download as "report_2026.pdf"
Res.Status(THTTPStatus.OK).Download(LStream, 'report_2026.pdf');
// CRITICAL MEMORY RULE: DO NOT FREE LStream here.
end;
The THorseResponse object takes ownership of any stream passed into SendFile, Download, or Render.
.Free or FreeAndNil on a stream after passing it to Res.SendFile, Res.Download, or Res.Render.