You are not logged in.
Pages: 1
Got exception when returning blob:
procedure TUserController.GetPhoto(const Ctxt: TSQLRestServerURIContext; const ID: TID);
var
blob: TSqlRawBlob;
begin
Server.RetrieveBlob(TORMUser, ID, 'Photo', blob);
Ctxt.ReturnBlob(blob, HTTP_PARTIALCONTENT, true, 'photo' + IntToStr(id));
end;
It seems Ctxt.Call is nil:
procedure TRestUriContext.ReturnBlob(const Blob: RawByteString;
Status: integer; Handle304NotModified: boolean; const FileName: TFileName;
CacheControlMaxAge: integer);
begin
if not ExistsIniName(pointer(fCall^.OutHead), HEADER_CONTENT_TYPE_UPPER) then <--- Exception here
Bug or feature?
Tried before with an out parameter, but response's Content-Type was 'application/json' instead of 'image/jpeg' and was refused by client:
procedure TUserController.GetPhoto(const ID: TID; out response: TSQLRawBlob);
begin
Server.RetrieveBlob(TORMUser, ID, 'Photo', response);
end;
How to define a Content-Type for interface based method?
Offline
What is this TUserController.GetPhoto signature?
If this is from an interface-based service, then Ctxt is the value sent by the client, not the current server-side execution context.
To return BLOB from an interface, use TServiceCustomAnswer kind of result.
See https://synopse.info/files/html/Synopse … #TITLE_478
Offline
Thank you for your help @ab, it's exactly what I need.
IUserController = interface(IInvokable)
function GetPhoto(const ID: TID): TServiceCustomAnswer;
...
TUserController = class(TInjectableObjectRest, IUserController)
public
function GetPhoto(const ID: TID): TServiceCustomAnswer;
...
function TUserController.GetPhoto(const ID: TID): TServiceCustomAnswer;
var
LPhoto: TSQLRawBlob;
begin
if Server.RetrieveBlob(TORMUser, ID, 'Photo', LPhoto) then
begin
result.Header := HEADER_CONTENT_TYPE+JPEG_CONTENT_TYPE;
result.Content := LPhoto;
result.Status := 200;
end
else
begin
result.Header := HTML_CONTENT_TYPE_HEADER;
result.Content := 'Not found';
result.Status := 404;
end;
end;
Offline
Pages: 1