2

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;
Mike L
  • 33
  • 5
  • 1
    if you change the type of `TmpStream` to `TMemoryStream` instead of `TFileStream`, then you can use the `.savetofile` method. – Freddie Bell May 07 '19 at 09:01
  • Thanks for you comment, but it is unclear to me where i can extract the received file (where is it being passed in to)? – Mike L May 07 '19 at 09:15
  • Is it not being passed into the Response.ContentStream? – Freddie Bell May 07 '19 at 13:42
  • I think the answer you're looking for might be here https://stackoverflow.com/questions/27155153 – Freddie Bell May 07 '19 at 13:43
  • @nolaspeaker no its nil, what is to be expected. Since the client makes the httprequest.post method with a stream in it. What I want is to extract the received data in my server (webbroker). I put that response.content in there just to test it. But it's not responding to a request, it is making the request – Mike L May 07 '19 at 15:01
  • @nolaspeaker I tried the suggested link already but It's not working for me. request.items.count is 0 for some reason – Mike L May 07 '19 at 15:08

0 Answers0