Return image (BLOB) in UDF Firebird / Delphi

0

I'm looking for a file (JPEG) and trying to return it in a Firebird UDF, through a BLOB field. It is running for small files, but large files the image is sent cut off. Anyone have any ideas?

function LoadPicture(AFilePath: PAnsiChar; ABlob: PBlob): PBlob; cdecl;
var
  img: TJPEGImage;
  APathStr: AnsiString;
  AStream: TMemoryStream;
  AOutPutStream: TStringStream;
  ALogFile: TextFile;
  tmpInteger: Integer;
  ARes: PAnsiChar;
begin
  AssignFile(ALogFile, 'C:\TesteDll.txt');
  Rewrite(ALogFile);
  img           := TJPEGImage.Create;
  AStream       := TMemoryStream.Create;
  AOutPutStream := TStringStream.Create('');
  try
    Writeln(ALogFile, AFilePath);
    try
      APathStr := Trim(string(AFilePath));
      if FileExists(APathStr) then begin
        img.LoadFromFile(APathStr);
        img.SaveToStream(AStream);
        AStream.Position := 0;
        Writeln(ALogFile, AStream.Size);
        EncodeStream(AStream, AOutPutStream);
      end;
      AOutPutStream.Position := 0;
      tmpInteger := Length(AOutPutStream.DataString);
      Writeln(ALogFile, tmpInteger+1);
      ARes       := ib_util_malloc((tmpInteger+1));
      StrPLCopy(ARes, AOutPutStream.DataString, tmpInteger);
      Writeln(ALogFile, ARes);
      Writeln(ALogFile, StrLen(ARes));
      ABlob^.PutSegment(ABlob^.BlobHandle, ARes, StrLen(ARes));
      Result := ABlob;
    except
      on e: Exception do
        Writeln(ALogFile, e.Message);
    end;
  finally
    CloseFile(ALogFile);
    FreeAndNil(img);
    FreeAndNil(AOutPutStream);
    FreeAndNil(AStream);
  end;
end;
    
asked by anonymous 13.03.2018 / 21:09

0 answers