You are not logged in.
Pages: 1
Hello!
I am new to mORMot, implementing Angular2 application and serving it via mORMot MVC. I want to serve binary file (jpg, pdf etc.) from DB blob as a response in MVC action. I do not use ORM part of the framework, so let's just say I have a TStream with data in it. I've managed to build my own "MVCViews" - view engine:
procedure TMVCViewsBinary.Render(methodIndex: Integer; const Context: Variant;
var View: TMVCView);
var
lStream : TStringStream;
begin
lStream := TStringStream.Create;
FillStreamWithImageDataFromMyDatabase(lStream, Context);
View.ContentType := 'image/jpeg';
View.Content := lStream.DataString;
lStream.Free;
end;
Works fine, but - stream loading logic placed in view engine doesn't look like a good idea. I've tried to return loaded stream object directly from MVC action, but all return params are serialized before passed to view engine - obviously, I don't want stream to be serialized on it's way, just 'rendered'.
Is there a better way to achieve my goal?
Offline
What type should I return in service method in order to return binary data with proper MIME declaration?
Offline
You should return TServiceCustomAnswer, take a look at documentation for more details.
Offline
Works well, thank you!
Offline
Pages: 1