Solved

Saving other file format in LONGBLOB (mySQL)

Posted on 2006-06-26
8
571 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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