Skip to content

Need exposure to TIdFormField #2

Description

@NamoRamana

Hi there,

Uncovered a need for the library to expose the TIdformField, specially when posting multi-part form. Here is the test case:

RestReq := TRestRequest.Create().Domain(Domain).Path(MethodPath);
params := TStringList.Create;
try
params.Add('someOne=' + someOne);
params.Add('someTwo=' + someTwo);
RestReq.FileParam('fil', fileNameWithPath);
RestReq.BeforeRequest := FOnBeforeReq;
RestReq.ConnectionTimeOut := TimeOut;
RestReq.ReadTimeOut := TimeOut;
RestResp := RestReq.Post(params);
if RestResp.ResponseCode = 200 then

when a value in a regular Name=Value parameter (and not the file param) is more than 71 characters, value is broken by "=CRLF" because the default content transfer is "quoted-printable".

One probable fix is(highlighted below), change the content transfer to BLANK after the form field is added:

function TRestRequest.createMultiPartFormDataStreamFromStringList(strings: TStringList;
aFileParams: TStringList): TIdMultiPartFormDataStream;
var
i: integer;
key, value: string;
begin
Result := TIdMultiPartFormDataStream.Create;
for i := 0 to strings.Count - 1 do
begin
key := strings.Names[i];
value := strings.ValueFromIndex[i];
Result.AddFormField(key, value).ContentTransfer := '';
end;
for i := 0 to aFileParams.Count - 1 do
begin
key := aFileParams.Names[i];
value := aFileParams.ValueFromIndex[i];
Result.AddFile(key, value, GetMIMETypeFromFile(value));
end;
end;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions