Hello Wagner; further to my project for creating the API using XData by reading the data from database and pass that through HTTP GET, I've implemented the method to read the image / pdf data stream and send it over using "TXDataOperationContext" very similar to sample GetPdfReport... but at the TMemoryStream I'm creating in "InternalGetMyPdfReport;" function to read the data is not clear. I thought "TXDataOperationContext" do manage the memory at the end.
The context also provides you with the request and response objects provided by the TMS Sparkle framework.
You can, for example, set the content-type of a stream binary response:
function TMyService.GetPdfReport: TStream;
begin TXDataOperationContext.Current.Response.Headers.SetValue('content-type', 'application/pdf');
Result := InternalGetMyPdfReport;
end;
I'm sorry, but your message is really confusing. Could you please provide the code you are using and the report/error you get from your memory leak tool?
qry.SQL.Text := 'SELECT access_id, doc_content FROM DOC_R WHERE queued_guid_ref = :rfid';
qry.ParamByName('rfid').AsGUID := FixGUID(refid); // FixGUID will return string
try
qry.Open;
except on E: Exception do
raise EXDataHttpException.Create(400, 'Data not found');
end;
if qry.IsEmpty then
begin
qry.Close;
Result:=VU.AnsiStringToStream(refid);
exit(nil);
end;
with qry do
begin
BlobField:= qry.FieldByName('doc_content') as TBlobField;
if not (BlobField.IsNull) then
begin
aStream:=TMemoryStream.Create;
BlobField.SaveToStream(aStream);
aStream.Position:=0;
Result.CopyFrom(aStream, aStream.Size);
aStream.Free;
end;
if active then
active:=false;
end;
end;
The "GetPdfDoc" method is working well and I can get the PDF file in client side. but when I close the server side application get the memory leak.