I am trying to allow clients to upload pdf/xls and jpg files to my webbroker server I have running. I think I am sending the correct content but I have no clue on how to extract the received data. I can't find an appropiate method to allow me to do this. I am using the provied Delphi httprequest.post method to connect to the server's back-end.
Below a code snippet:
Client
try
NetHTTPClient.ContentType := 'application/pdf';
//NetHTTPRequest.ResponseTimeout := 600000;
tmpPDFFile := TFileStream.Create(pFilename, fmOpenRead);
//tmpPDFFile.Position:=0;
GetDossierIDAndDagboek;
tmpURL := MyURL + 'uploadAnyFile' + '?key=' + MyAPIKey + '&CLID=' + MyCLID + '&DOSID=' + tmpDOSID + '&JOURNAL=' + tmpDagboek + '&FILETYPE=' + pFileExstension;
NetHTTPRequest.ContentStream := tmpPDFFile;
NetHTTPRequest.Post(tmpURL,tmpPDFFile);
if HTTPLastStatusCode = 500 then begin
WriteToLog('Er ging iets mis bij het verwerken van document ' + pFilename);
end;
if HTTPLastStatusCode = 200 then begin
DeleteFile(pFilename);
end;
except
on e : exception do begin
WriteToLog(e.Message);
end;
end;
Server
procedure TWebModule1.WebModule1UploadAnyFileAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
tmpJournal, tmpFileType : string;
tmpCLID, tmpDOSID : integer;
tmpStream : TFileStream;
tmpStr:string;
tmpX:integer;
begin
try
Handled := true;
Response.StatusCode := 200;
tmpCLID := StrToInt(Request.QueryFields.Values['CLID']);
tmpDOSID := StrToInt(Request.QueryFields.Values['DOSID']);
tmpJournal := Request.QueryFields.Values['JOURNAL'];
tmpFileType := Request.QueryFields.Values['FILETYPE'];
CodeSite.Send('bestand opgeslagen');
request.Files.Count;
tmpStream := Response.ContentStream;
// TmpStream := request.ReadString;
if tmpFileType = 'pdf' then begin
//tmpStr.SaveToFile('c:\temp\test.pdf');
end;
if (tmpFileType = 'jpeg') OR (tmpFileType = 'jpg') then begin
end;
if (tmpFileType = 'xlsx') OR (tmpFileType = 'xls') then begin
end;
except
on e : exception do begin
end;
end;
end;