TsgcWebSocketHTTPServerEvents › OnHTTPUploadBeforeCreatePostStream

OnHTTPUploadBeforeCreatePostStream Event

Fires after the request headers have been read and before the POST stream is created so the upload can be accepted or rejected.

Syntax

public event TsgcWSHTTPBeforeCreatePostStreamHandler OnHTTPUploadBeforeCreatePostStream;
// delegate void TsgcWSHTTPBeforeCreatePostStreamHandler(TObject Sender, TsgcWSConnection Connection, TStrings aHeaders, out bool Accept)

Default Value

Remarks

OnHTTPUploadBeforeCreatePostStream runs before the component allocates the POST stream (either a TMemoryStream or a TFileStream based on HTTPUploadFiles.StreamType) where the body of an incoming upload will be stored. Inspect aHeaders (Content-Type, Content-Length, Authorization...) and the Connection to decide whether the upload is allowed: set Accept to True to keep receiving the body, or False to discard it and return an error to the client. Use this hook to enforce size limits, reject unauthorized uploads early, or validate the Content-Type before a large multipart/form-data body is buffered on disk.

Example


void OnHTTPUploadBeforeCreatePostStream(TObject Sender, TsgcWSConnection Connection,
  TStrings aHeaders, ref bool Accept)
{
  int length;
  int.TryParse(aHeaders.Values["Content-Length"], out length);
  Accept = length <= 100 * 1024 * 1024;
}

Back to Events