Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get filename of uploaded file during POST
I am implementing a file upload function similar to the PostDataDemo ( 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.
Within the content handler you have various information about the file, not only the temporary file name.

Here is the code form that example:

function TContentXML.Execute(aRequest: THttpRequest; aReply: THttpReply; const aPathname: string; aSession: TIWApplication;
  aParams: TStrings): boolean;
  xFile: THttpFile;
  xml: string;
  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;

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).

Forum Jump:

Users browsing this thread: 1 Guest(s)