Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TWinHttpAPI.OnUpload event #198

Merged
merged 1 commit into from May 13, 2019

Conversation

Projects
None yet
2 participants
@ysair
Copy link
Contributor

commented May 13, 2019

example

function TPostThread.OnHttpUpload(Sender: TWinHttpAPI; CurrentSize,
  ContentLength: DWORD): boolean;
begin
  //update ui
  Synchronize(procedure
    begin
      Form1.ProgressBar.Max :=  ContentLength;
      Form1.ProgressBar.Position  :=  CurrentSize;
      Form1.ProgressBar.Update;
    end);
  //cancelled?
  Result  :=  not FCancel;
end;

procedure TPostThread.Execute;
var
  URI: TURI;
  http : TWinHttpAPI;
  inData, outData, inHeaders, outHeaders: SockString;
begin
  inherited;
  if URI.From('http://localhost/upload') then
  begin
    http  :=  TWinHTTP.Create(URI.Server, URI.Port, URI.Https);
    //http  :=  TWinINet.Create(URI.Server, URI.Port, URI.Https);
    try
      http.OnUpload :=  OnHttpUpload;
      inData  :=  StringFromFile('test.txt');
      if http.Request(URI.Address, 'POST', 0, inHeaders, inData, '',
          outHeaders, outData) = STATUS_SUCCESS then
      begin
        //post succeed
      end;
    finally
      http.Free;
    end;
  end;
end;
@synopse
Copy link
Owner

left a comment

sounds fine! great!

@synopse synopse merged commit 4edf230 into synopse:master May 13, 2019

synopse pushed a commit that referenced this pull request May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.