fabriciocolombo / delphi-rest-client-api

A Delphi REST client API to consume REST services written in any programming language.
Apache License 2.0
380 stars 182 forks source link

Supports requests using multipart/form-data #84

Closed fernand-o closed 7 years ago

fernand-o commented 7 years ago

This will allow sending forms with file attachments, by declaring a class that represents the form fields and inherits from TMultiPartFormData. File fields must be TMultiPartFormAttachment, wich allows passing a file path or a stream with the file contents in the constructor.

Declaration:

TRequestData = class(TMultiPartFormData)
  Name: string;
  Document: TMultiPartFormAttachment;
end;

Usage:

 Request := TRequestData.Create;
 Request.Name := 'Fernando'; 
 Request.Document := TMultiPartFormAttachment.Create('c:\sample.txt', 'text/plain', 'sample.txt');

 Result := RestClient.Resource(URL).Post<TResultType>(Request);