RTC Forums
November 24, 2024, 12:42:33 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: TRTCDataRequest ResponseDone event  (Read 4290 times)
dpcroghan
RTC Expired
*
Posts: 17


« on: December 19, 2013, 11:17:38 PM »

Hi Danijel,

At the end of a successful post to the server I'd like to delete the local file if the status is 200. Before the post I set the TRTCDataRequest  drPutFile.Request.Info.asText['file'] to the path to the local file to upload. However, trying to read this property in the ResponseDone event of the TRTCDataRequest returns an empty string.

I'm trying to avoid using a private global variable to hold the local file name and path, is there any other way. I don't fully understand the RTC class framework yet, so maybe I'm missing something.

Thanks,
dp

procedure TForm1.drPutFileResponseDone(Sender: TRtcConnection);
var
  rdsClient : TRtcDataClient absolute Sender;
begin
  pb1.Position := 0;

  // if status of put good, do we want to delete local file at this point?
  if (rdsClient.Response.StatusCode = 200) then
  begin
    mmResult.Lines.Add('File was uploaded.');
    mmResult.Lines.Add('Deleting the local file unless it has to be sent to other locations.');
    // if not some flag not to delete then
    mmResult.Lines.Add('File to delete: ' + drPutFile.Request.Info.asText['file']); // <-- empty string
  end
  else
  begin
    mmResult.Lines.Add('File was not uploaded successfully.');
    mmResult.Lines.Add('Status: ' + IntToStr(rdsClient.Response.StatusCode) + rdsClient.Response.StatusText);
  end;
end;
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: December 19, 2013, 11:32:59 PM »

The complete "Request" object is moved from the "TRtcDataRequest" component to the connection component when you call the "Post" method. First, it will be placed into the request queue, then (when the request starts being processed and one of the RTC events is called), it will be available through the "Request" property of the connection component. In short, you can access the "Request" object the same way you are already accessing the "Response" object, through the TRtcDataClient(Sender) parameter passed to the RTC event.

procedure TForm1.drPutFileResponseDone(Sender: TRtcConnection);
var
  rdsClient: TRtcDataClient absolute Sender;
begin
  pb1.Position := 0;

  // if status of put good, do we want to delete local file at this point?
  if (rdsClient.Response.StatusCode = 200) then
  begin
    mmResult.Lines.Add('File was uploaded.');
    mmResult.Lines.Add('Deleting the local file unless it has to be sent to other locations.');
    // if not some flag not to delete then
    mmResult.Lines.Add('File to delete: ' + rdsClient.Request.Info.asText['file']); // <-- change here
  end
  else
  begin
    mmResult.Lines.Add('File was not uploaded successfully.');
    mmResult.Lines.Add('Status: ' + IntToStr(rdsClient.Response.StatusCode) + rdsClient.Response.StatusText);
  end;
end;

Best Regards,
Danijel Tkalcec
Logged
dpcroghan
RTC Expired
*
Posts: 17


« Reply #2 on: December 20, 2013, 03:54:34 PM »

Thank you Danijel for a speedy reply.

Happy Holidays
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.