Solved

Saving other file format in LONGBLOB (mySQL)

Posted on 2006-06-26
8
574 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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Delphi IDE crash without error message ... 7 121
Convert a string into a TDateTime 5 73
Delphi: sending SMS on android platform 1 69
firemonkey Android Listview Sort items 7 74
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

726 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