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

WinHTTP and TIdMultipartFormDataStream uploads #59

Closed Timothyoverton closed 8 years ago

Timothyoverton commented 8 years ago

Hi Guys,

I'm still trying to integrate your rest client. I have 1 last hurdle.

We are uploading a file in chunks using TIdMultipartFormDataStream and TIdHttp from Indy, we are making a post for each chunk that is uploaded. Is this possible to do this with WinHTTP and your wrapper?

Thanks, Tim

thomaserlang commented 8 years ago

Try to copy the TIdMultiPartFormDataStream to a TMemoryStream and remember to set the correct Content-Type header. Then post it. The result will be a string.

Something like this:

data := TIdMultiPartFormDataStream.Create;
content := TMemoryStream.Create;
try
    with data.AddFile('doc', 'test.txt', '') do
    begin
      HeaderCharset := 'utf-8';
      HeaderEncoding := '8';
    end;
    content.CopyFrom(data, 0);
    s := restclient.Resource('http://localhost/documents')
        .ContentType(data.RequestContentType)
        .Post(content);
finally
    data.free;
    content.free;
end;
Timothyoverton commented 8 years ago

Right! That looks promising I'll give it a try - thanks!