You are not logged in.
Pages: 1
Hi! I already have asked similar question but didn't had the time to try everything out at this time, so here i am again.
In my TMVCApplication, I'd like a function (or procedure doesn't matter) to return a pdf from stream.
So after search and try, I'm with
function Test(const id: Integer): TServiceCustomAnswer;
begin
[...]
Result.Header := BINARY_CONTENT_TYPE_HEADER;
Result.Content := StreamToRawByteString(TMemoryStream(pdfExport.Stream));
end;
From what I understand, doesn't this should be enough? But when I link to Test?id=22 well it redirect me to Test.html... (and create a mustache template)
I also have tried with CurrentServiceContext() and is Request member, couldn't figure out how to do it.
If someone could point me in the right direction I would greatly appreciate.
Offline
You can register separate service method for downloading files.
procedure TMyApp.Start(aRestModel: TSQLRest);
begin
inherited Start(aRestModel, TypeInfo(IMyApp));
...
TSQLRestServer(aRestModel).ServiceMethodRegister('DownloadFile', DownloadFile, True);
end;
procedure TMyApp.DownloadFile(Ctxt: TSQLRestServerURIContext);
begin
// If you need authentification
if CurrentSession.CheckAndRetrieve(@LSessionData, TypeInfo(TCookieData)) <> 0 then
begin
Ctxt.Returns(...);
end
else
Ctxt.Error('', HTML_FORBIDDEN);
end;
Offline
Thanks for your reply and your time ! It worked as expected.
Offline
Pages: 1