Atozed Forums
How to get filename of uploaded file during POST - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: How to get filename of uploaded file during POST (/thread-3072.html)



How to get filename of uploaded file during POST - dbrain23 - 03-18-2023

I am implementing a file upload function similar to the PostDataDemo (https://github.com/Atozed/IntraWeb/tree/master/15/Delphi/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.


RE: How to get filename of uploaded file during POST - Alexandre Machado - 03-21-2023

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