[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 579
  • Last Modified:

Saving other file format in LONGBLOB (mySQL)

Hi,

 I have a field named "Media" with LongBlob datatype. I store image, audio, video or any file format in this "Media" field. my question now is how to convert the data stored inside "Media" back to its original format and save it in my harddrive?

I already have the code in saving and loading an image(jpg or bmp) file in my "Media" field. My problem also is in how to save and load other file format aside from images inside my LongBlob field.


------------------------------------------------------------------
I  used this to save image in my Media (blob fieldtype)
   ms := TMemoryStream.Create;
   Image1.Picture.Graphic.SaveToStream(ms);
   ms.Position := 0;
   TBlobField(oTable.FieldByName('MEDIA')).LoadFromStream(ms);
-------------------------------------------------------
And used this to load my image in the TIMAGE
Procedure TfDigitalMed.InitializeForm;
var
  ms : TStream;
  gr : TBitmap;
begin
  ms := oTable.CreateBlobStream(oTable.FieldByName('MEDIA'), bmRead);
  gr := TBitmap.Create;
  gr.LoadFromStream(ms);
  Image1.Picture.Bitmap.Assign(gr);
  gr.Free;
  ms.Free;
end;
---------------------------------------------------------------
0
ryan_sabarre
Asked:
ryan_sabarre
  • 4
  • 3
1 Solution
 
ryan_sabarreAuthor Commented:
THANKS AGAIN
0
 
Pierre CorneliusCommented:
...
var fs: TFileStream;
begin
  fs := TFileStream.Create(SomeFileName, fmOpenRead);
  try
   fs.Position := 0;
   TBlobField(oTable.FieldByName('MEDIA')).LoadFromStream(fs);
  finally
    fs.Free;
  end;
...
0
 
ryan_sabarreAuthor Commented:
can you please complete the code. :-) is there any savetofile method capability?
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
JDSkinnerCommented:
Take a look at the following link
Called 'save a file to a TBlobStream and read it back'
http://www.swissdelphicenter.ch/en/showcode.php?id=1271
0
 
Pierre CorneliusCommented:
for saving you could do this:

...
var fs: TFileStream;
begin
  fs:= TFileStream.Create(SomeFilename, fmCreate);
  try
    TBlobField(oTable.FieldByName('MEDIA')).SaveToStream(fs);    
  finally
    fs.Free;
  end;
0
 
ryan_sabarreAuthor Commented:
Hi last one, how can i clear value inside "Media" field?

 oTable.FieldByName('MEDIA')).asvariant:=nil; ???

0
 
Pierre CorneliusCommented:
No, do this:

  TBlobField(oTable.FieldByName('MEDIA')).Clear;
0
 
ryan_sabarreAuthor Commented:
THANKS A LOT PierreC!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now