procedure SendFilesREST(const PdfFile, XmlFile: string);
var RESTClient:= TRESTClient;
RESTRequest:= TRESTRequest;
RESTResponse:= TRESTResponse;
MultipartData: TMultipartFormData;
begin
RESTClient:= TRESTClient.Create(nil);
RESTRequest:= TRESTRequest.Create(nil);
RESTResponse:= TRESTResponse.Create(nil);
RESTRequest.Client:= RESTClient;
RESTRequest.Response:= RESTResponse;
RESTRequest.Method:= rmPost;
RESTRequest.ConnectTimeout:= -1;
RESTRequest.ReadTimeout:= -1
RESTRequest.Params.AddHeader('Accept', 'application/json');
RESTRequest.Params.AddHeader('X-
Api-Key', 'My-
API-Key');
RESTRequest.Params.AddHeader('Content-Type', 'multipart/form-data');
MultipartData:= TMultipartFormData.Create;
try
FRESTClient.BaseURL:= 'https://<provider>/Documents/Outbox';
FRESTRequest.Method:= rmPOST;
if PdfFile<>'' then
MultipartData.AddFile('files', PdfFile, GetMIMETypeFromFile(PdfFile));
if XmlFile<>'' then
MultipartData.AddFile('files', XmlFile, GetMIMETypeFromFile(XmlFile));
FRESTRequest.AddBody(MultipartData);
FRESTRequest.Execute;
if FRESTResponse.Status.Success then begin
// ...
end;
finally
RESTClient.Free;
RESTRequest.Free;
RESTResponse.Free;
MultipartData.Free;
end;
end;