c'est vrai
your solution seems to be working mars, but it's a little dirty, so i decided to study a little more before to accept it.
our problem is closing the file a bit earlier, but to be still able to read the name of the file.
i noticed the name of the file is already kept in uploadDest, so every place where i used getFilename(data.f^) can be replaced by data.uploadDest.
...and now we can safely close the file before the event call
this solution seems to be better
function runEventScript(event:string; table:array of string):string; overload;
...
try
if isReceivingFile(data) then
begin
// we must encapsulate it in a Tfile to expose file properties to the script. we don't need to cache the object because we need it only once.
md.f:=Tfile.createTemp(data.uploadDest);
and clearly
closeUploadingFile();
if data.uploadFailed = '' then runEventScript('upload completed')
else runEventScript('upload failed');