Skip to content

Commit

Permalink
add file method
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Aug 4, 2023
1 parent f055a12 commit a44409f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/RESTRequest4D.Request.Client.pas
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,12 @@ function TRequestClient.AddField(const AFieldName: string; const AValue: string)
function TRequestClient.AddFile(const AFieldName: string; const AFileName: string; const AContentType: TRESTContentType): IRequest;
begin
Result := Self;
if not FileExists(AFileName) then
Exit;
{$IF COMPILERVERSION >= 32.0}
if not FileExists(AFileName) then
Exit;
FRESTRequest.AddFile(AFieldName, AFileName, AContentType);
{$ELSE}
raise Exception.Create('Method not implemented for your Delphi version. Try changing the engine or submitting a pull request.');
{$ENDIF}
end;

Expand All @@ -176,9 +178,9 @@ function TRequestClient.AddFile(const AFieldName: string; const AValue: TStream;
{$ENDIF}
begin
Result := Self;
if not Assigned(AValue) then
Exit;
{$IF COMPILERVERSION >= 33.0}
if not Assigned(AValue) then
Exit;
lFileName := Trim(AFileName);
if (lFileName = EmptyStr) then
lFileName := AFieldName;
Expand All @@ -191,6 +193,8 @@ function TRequestClient.AddFile(const AFieldName: string; const AValue: TStream;
Kind := TRESTRequestParameterKind.pkFILE;
ContentType := AContentType;
end;
{$ELSE}
raise Exception.Create('Method not implemented for your Delphi version. Try changing the engine or submitting a pull request.');
{$ENDIF}
end;

Expand Down

0 comments on commit a44409f

Please sign in to comment.