有没有一种方法可以使用httprequest.post方法发送TFileStream并将其提取到Webbroker中?

时间:2019-05-07 07:10:29

标签: delphi webrequest tfilestream webbroker

我正试图允许客户将pdf / xls和jpg文件上载到我正在运行的webbroker服务器。我想我发送的内容正确,但是我不知道如何提取接收到的数据。我找不到合适的方法来执行此操作。我正在使用提供的Delphi httprequest.post方法连接到服务器的后端。

下面的代码段中:

客户

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;

服务器

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;

0 个答案:

没有答案