Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Saving other file format in LONGBLOB (mySQL)

Posted on 2006-06-26
8
573 Views
Last Modified: 2010-04-05
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
Comment
Question by:ryan_sabarre
  • 4
  • 3
8 Comments
 

Author Comment

by:ryan_sabarre
ID: 16981745
THANKS AGAIN
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16981751
...
var fs: TFileStream;
begin
  fs := TFileStream.Create(SomeFileName, fmOpenRead);
  try
   fs.Position := 0;
   TBlobField(oTable.FieldByName('MEDIA')).LoadFromStream(fs);
  finally
    fs.Free;
  end;
...
0
 

Author Comment

by:ryan_sabarre
ID: 16983447
can you please complete the code. :-) is there any savetofile method capability?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 4

Expert Comment

by:JDSkinner
ID: 16983648
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
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 50 total points
ID: 16984166
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
 

Author Comment

by:ryan_sabarre
ID: 16984363
Hi last one, how can i clear value inside "Media" field?

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

0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 16985928
No, do this:

  TBlobField(oTable.FieldByName('MEDIA')).Clear;
0
 

Author Comment

by:ryan_sabarre
ID: 16989295
THANKS A LOT PierreC!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 110
Convert GUI app into console app for Win32 Env 5 109
Multiple image collision 13 80
Delphi and Access based Enumeration 9 70
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question