Malformed blobs (jpg) - zeos + firebird lazarus / 16-Databases ---------------------------------------------------------------------- tomek1 · 2019-01-28 12:57 Hi I'm inserting jpg's to blob field, everything seems to work properly, but blob content is malformed. Here's the sample code: Code: [Select]  ZQuery1.SQL.Text := 'insert into PLATES (ID,'                     + '                    PLATE_PIC)'                     + 'values (gen_id(GEN_PLATES, 1),'                     + '        :PLATE_PIC)';   Stream := TMemoryStream.Create;   try     Stream.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'test.jpg');     ZQuery1.ParamByName('PLATE_PIC').LoadFromStream(Stream, ftBlob);     //ZQuery1.ParamByName('PLATE_PIC').SetBlobData(Stream.Memory, Stream.Size);     ZQuery1.ExecSQL;   finally     Stream.Free;   end; Below printscreens with hex content of the file, and blob in db. Content differs more, not only first 4 bytes. Firebird 2.5.2, charset utf8, PLATE_PIC is blob subtype binary. Regards, Tomek ---------------------------------------------------------------------- balazsszekely · 2019-01-28 13:18 Try to set Stream.Position to 0 after Stream.LoadFromFile. ---------------------------------------------------------------------- rvk · 2019-01-28 13:36 You might even be able to just use LoadFromFile() directly. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TBlobField( ZQuery1.ParamByName('PLATE_PIC')).LoadFromFile(ExtractFilePath(ParamSt r(0)) + 'test.jpg');ZQuery1.ExecSQL; ---------------------------------------------------------------------- tomek1 · 2019-01-28 14:31 Quote from: GetMem on January 28, 2019, 02:18:13 pmTry to set Stream.Position to 0 after Stream.LoadFromFile. It doesn't fix the problem. Quote from: rvk on January 28, 2019, 02:36:31 pmYou might even be able to just use LoadFromFile() directly. The code above is actually a test case, real app gets the the pic in stream. Regards, Tomek ---------------------------------------------------------------------- rvk · 2019-01-28 14:47 Looking at those "?" I expect every $ff and subsequent character is converted (because of UTF-8). That shouldn't happen but I'm not sure what happens in the parameters in Zeoslib. Can you check what the type is of the parameter ZQuery1.ParamByName('PLATE_PIC').DataType? It should be ftBlob. Otherwise you could clear and create the parameters by hand. I also never worked with parameters to directly insert a blob. You could try to do a SELECT ID, PLATE_PIC FROM PLATES and do a ZQuery1.Insert and fill in the fields at that point. ---------------------------------------------------------------------- balazsszekely · 2019-01-28 15:26 I used the following code for years and it works fine, you have to adapt it to your needs though: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  St: TStream;begin  SQLQuery1.Edit;  St := SQLQuery1.CreateBlobStream(SQLQuery1.FieldByName('PICTURE'), bmWrite); //PICTURE --> BLOB SUB_TYPE 0 SEGMENT SIZE 80(binary)  try    Image1.Picture.SaveToStream(St);    SQLQuery1.ApplyUpdates;    SQLTransaction.CommitRetaining;  finally    St.Free;  end;end; ---------------------------------------------------------------------- tomek1 · 2019-01-29 09:28 Quote from: rvk on January 28, 2019, 03:47:50 pmLooking at those "?" I expect every $ff and subsequent character is converted (because of UTF-8). That shouldn't happen but I'm not sure what happens in the parameters in Zeoslib. Can you check what the type is of the parameter ZQuery1.ParamByName('PLATE_PIC').DataType? It should be ftBlob. Otherwise you could clear and create the parameters by hand. I also never worked with parameters to directly insert a blob. You could try to do a SELECT ID, PLATE_PIC FROM PLATES and do a ZQuery1.Insert and fill in the fields at that point. DataType of param is fbBlob. Select/Insert/FieldByName isn't preferred nor optimal approach, but it works! (the ZQuery1 's only purpose is batch insert). Thank you both for help. Regards, Tomek ---------------------------------------------------------------------- EgonHugeist · 2019-01-29 09:39 Hi tomek1, Which version did you use? There was a regression(Buf overrun of 4Bytes with the Currency values) in the SVN version, i fixed yesterday evening. If you don't use SVN than please open a ticked in the Zeos bugtracker https://sourceforge.net/p/zeoslib/tickets/ else update from SVN. ---------------------------------------------------------------------- tomek1 · 2019-01-30 11:24 Hi I was using 7.2.1-rc. I've tested 7.2.4-stable - problem still remains. Latest version (snapshot) solves the problem! Thx for help. Regards, Tomek