Solved

Saving other file format in LONGBLOB (mySQL)

Posted on 2006-06-26
8
575 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
[X]
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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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