i need a function in a datasnap-server, which returns a .zip file. So i started with:
function TGetData.getZip (): TFileStream;
begin
result := TFileStream.Create('test.zip', fmOpenRead and fmShareDenyWrite);
end
This works fine, but datasnap doesn't free it, so i get a memory leak error.
Next try: I started at "TWebModule1.WebModuleAfterDispatch". I thought it could help to send my response with "response.SendResponse;" and free my stream on my own. So here a short version:
procedure TWebModule1.WebModuleAfterDispatch(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
test : TFileStream;
begin
response.ContentType := 'application/x-zip-compressed';
test := TFileStream.Create('test.zip', fmOpenRead);
response.ContentStream := test;
response.CustomHeaders.Values['Content-Disposition'] := 'attachment; filename=test12.zip';
response.SendResponse; //Also sendStream didn't help
test.Free;
end;
This is nearly the solution i think, but the datasnap-server sends html-code after my stream was sent and this is written at the end of the file.
I know, the datasnap-server doenst support TFileStream. Instead i should use TDBXStreamValue, but there seems to be no working example...
Has any one expirience with such a problem?