TsgcWebSocketHTTPServerEvents › OnHTTPUploadBeforeSaveFile

OnHTTPUploadBeforeSaveFile Event

Fires before a file extracted from a multipart/form-data upload is saved to disk so the name and path can be customized.

Syntax

property OnHTTPUploadBeforeSaveFile: TsgcWSHTTPUploadBeforeSaveFileEvent;
// TsgcWSHTTPUploadBeforeSaveFileEvent = procedure(Sender: TObject; var aFileName, aFilePath: string) of object

Default Value

Remarks

When HTTPUploadFiles.StreamType is pstFileStream and HTTPUploadFiles.RemoveBoundaries is True, the server extracts each file from the received multipart/form-data boundaries and saves it to disk automatically. OnHTTPUploadBeforeSaveFile is raised for every file just before it is written, giving the application a chance to override the destination: modify aFileName (defaults to the original client file name) or aFilePath (defaults to HTTPUploadFiles.SaveDirectory) to pick a different target. Use it to sanitize untrusted names, route uploads into per-user folders, or prefix a timestamp to avoid collisions.

Example


procedure OnHTTPUploadBeforeSaveFileEvent(Sender: TObject; var aFileName: string;
  var aFilePath: string);
begin
  if aFileName = 'test.jpg' then
    aFileName := 'custom_test.jpg';
end;

Back to Events