TsgcWebSocketHTTPServer › Events › OnHTTPUploadBeforeSaveFile
Fires before a file extracted from a multipart/form-data upload is saved to disk so the name and path can be customized.
public event TsgcWSHTTPUploadBeforeSaveFileEventHandler OnHTTPUploadBeforeSaveFile;
// delegate void TsgcWSHTTPUploadBeforeSaveFileEventHandler(TObject Sender, out string aFileName, out string aFilePath)
—
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.
private void OnHTTPUploadBeforeSaveFileEvent(TObject Sender, ref string aFileName,
ref string aFilePath)
{
if (aFileName == "test.jpg")
aFileName = "custom_test.jpg";
}