How to get filename of uploaded file during POST

<< Click to Display Table of Contents >>

Navigation:  Forum >

How to get filename of uploaded file during POST

Forum link

 


 

03-18-2023, 07:52 AM:

 

I am implementing a file upload function similar to the PostDataDemo (https://github.com/Atozed/IntraWeb/tree/...stDataDemo) and is working fine. However, I am wondering if there is a way to extract the filename in the ContentHandler? The aRequest.File object only contains the temporary filename (.tmp) and not the original filename.

 


 

03-21-2023, 06:39 AM:

 

Within the content handler you have various information about the file, not only the temporary file name.

 

Here is the code form that example:

 

Code:

 

function TContentXML.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;

 

  aParams: TStrings): boolean;

 

var

 

  xFile: THttpFile;

 

  xml: string;

 

begin

 

  Result := False;

 

  if aRequest.Files.Count = 1 then begin

 

    xFile := THttpFile(aRequest.Files[0]);

 

    xml := TIWTextFileReader.ReadAllText(xFile.TempPathName);

 

    aReply.WriteString(ClassName + '.Execute - Content received: ' + xml);

 

    Result := True;

 

  end;

 

end;

 

 

 

These are the properties that you can get from the "xFile" variable above:

 

    property FileName: TFileName;

 

    property TempPathName: TFileName;

 

    property ContentType: string;

 

    property FileSize: Int64;

 

    property FieldName: string;

 

    property FileSize_WebApi: Int64;

 

    property LastModified_WebApi: TDateTime;

 

    property MIMEType_WebApi: string;

 

The _WebApi suffixed properties may or may not be available (it depends on the browser).