Friday 15 August 2014

delphi - Saving blob field from Advantage DB to file -


I have a problem retrieving the Blob field with images, then save it in the file.
Downloaded file does not seem to be in the correct format; If I open it with the hex editor, then in the word @robobb @

what could be wrong?

  bg: = TAdsBlobStream.Create (adsQuery1.FieldByName ('page' as TBlobField, bmReadWrite); F: = TMemoryStream.create; bg rank: = 0; F.CopyFrom ( Bg, bg.size); F.SaveToFile ('c: \ tmp \ db \ img \' + IntToStr (n) + '.Jpg'); f.free;   

Thanks

I just used the following code to write the small (9 K) JPEG in the ADS Blob Field ADSTP Through it, reading it in an adbobstream and writing it on disk in a different place, and all worked fine. New copy of the image The Windows Picture Viewer is okay, and I do not see any unchanging characters with any hex viewer.

  // The ARC 32 Table Test (ID integer, picture Blob);   

TADSSettings on a new blank VCL form, TADSQuery , and two plain TButton These excluded components are onclick handlers (apparently both handlers have hard-coded file names And should be replaced by actual filenames on your machine):

  Process TForm1.Button1Click (Sender: Tubbed); Var Blob: Tedsblobstream; Strm: TFileStream; Tbl: TAdsTable; Start Tbl: = TAdsTable. Cut (zero); Try Tbl.DatabaseName: = AdsQuery1.DatabaseName; Tbl.TableType: ttAdsCDX; Tbl.TableName: = 'Test.dbf'; Tbl.Open; Tbl.Edit; Blob: TB.CreateBlobStream (AdsQuery1.Fields [1], BMDrite) as TAdsBlobStream; Try Storm: = TFileStream.Create ('E: \ Test \ Images \ Big Folder .Jpg', fmOpenRead); Try Blob.CopyFrom (Strm, Strm.Size); Finally Strm.Free; End; Blob in the end free; End; Finally Tbl.Post; Tbl.Close; Tbl.Free; AdsQuery1.Open; End; End; Process TForm1.Button2lick (Sender: Tubbed); Var Blob: Tedsblobstream; Strm: TFileStream; Start AdsQuery1.SQL.Text: = 'Selection ID, picture from exam'; AdsQuery1.Open; Blob: = AdsQuery1.CreateBlobStream (AdsQuery1.fields [1], BMRD) as TAdsBlobStream; Try STRM: = TFileStream.Create ('E: \ TempFiles \ BigFolder.jpg', fmCreate); Try strm.CopyFrom (Blob, Blob.Size); Finally Strm.Free; End; Blob in the end free; End; End;   

Run the app, and click on the button 1 to insert an image in the Test table, then read it back and it's on a disk To write a new file, click on button2 .

No comments:

Post a Comment