Loading images stored as BLOBs in MySQL

Hello,
For various reasons, I would prefer to store binary data like images and videos as BLOBs within a MySQL database and have Flash retrieve that content directly from the database as opposed to getting it from a URL on a fileserver. So, I have written a PHP script that Flash calls which does a database query and returns the bitmap data from the BLOB. I have verified that the image data is being sent from the database through the PHP, but Flash either doesn't display the image or gives me an error saying that it is an unknown type.
Here is the AS3:
var imageLdr:Loader = new Loader();
//imageLdr.dataFormat = "binary";
imageLdr.load(new URLRequest("http://www.XXXXXXXXXX.com/cgi/getToken.php"));
imageLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, loadImage, false, 0, true);
function loadImage(evt:Event):void {
    trace("Now in loadImage...");
    tokenHolder.addChild(imageLdr);
    addChild(tokenHolder);
    trace("loadImage complete...");
Here is the getToken.php file code:
<?php
$hostname = "dbhost";
$username = "username";
$password = "pword";
mysql_connect($hostname, $username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database'),history.go(-1)</script></html>");
mysql_select_db($username);
$query = "SELECT content FROM media WHERE id=2";
$result = mysql_query($query);
$data = mysql_result($result, 0);
$im = imagecreatefromstring($data);
if ($im !== false) {
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);
else {
    echo 'An error occurred.';
?>
Is there a way to get Loader() to accept bitmap image data that is retrieved from a BLOB in a database? Should I try to get PHP to mimic the response from an HTTP server or is there another way to load bitmap data stored as a BLOB into a display object?
Thanks!

Hey
Thanks for sharing your problem and how you get data as image in php. It gave me clue about my problem about getting blob info from database to as3 and displat it as image. So what i did is:
In this fuction;
function  loadImage(evt:Event):void {
    trace("Now in loadImage...");
     tokenHolder.addChild(imageLdr);
    addChild(tokenHolder);
     trace("loadImage complete...");
I changed it to:
public function loadImage(evt:Event):void {
                trace("Now in loadImage...");
                img= evt.currentTarget.content as Bitmap;
                trace("loadImage complete...");
img is a Bitmap variable and I used Image component and stated its source as imgg ( source={img} )
I hope you can solve your problem
Have a good day...

Similar Messages

  • Problem in displaying images stored in Blob variable

    Hi all,
    I have a requirement where i need to retrieve the image stored in Blob variable in DB and display the image in JSP page.
    I have written the below code to achieve this, it works fine
    In JSP, I am calling a action in the <img tag
    <img src='downloadPhoto.page?method=getPhotoInBytes&accessoryModelPictures.id.accessoryNumber=${photo.id.accessoryNumber}/> In my controller class
    InputStream inputStream=accessoryPicturesLOB.getPicture().getBinaryStream();
    byte[] theBytes = new byte[inputStream.available()];
    inputStream.read(theBytes);
    response.setContentType("image/jpg");
    response.getOutputStream().write(theBytes);But the problem is, *if i right click on the image and select save picture as option i get a error saying "The system cannot find the specified file "*
    Can you please tell me what is wrong in my approach/code
    Is there any better approach to display image that is store in Blob variable ?
    Please help on this.
    Thanks in advance.

    You need at least to set the filename in the content disposition header.

  • How to display and save a picture stored as BLOB in MySQL database in Jsp?

    Hello i am doing a dataentry form where in i will display the picture stored as Blob in MySQL database to the browser. The form also allow changing the picture and updating the picture Blob in the database.
    How can i do it? I try this
    <img src'"<%=rs.getBlob("picture")%> but it doesn't display the picture.
    another thing, how can i save it in the database, if is use the file field in the html form?
    thanks in advance for your help.

    Hello i am doing a dataentry form where in i will display the picture stored as Blob in MySQL database to the browser. The form also allow changing the picture and updating the picture Blob in the database.
    How can i do it? I try this
    <img src'"<%=rs.getBlob("picture")%> but it doesn't display the picture.
    another thing, how can i save it in the database, if is use the file field in the html form?
    thanks in advance for your help.

  • Inserting images stored as BLOB in table to Oracle Report(10G)

    We have some oracle reports(rdf) built in Oracle 10g. Now we are planning to update these reports to include images stored as pdf's on file system. We have loaded these pdf's as blob into tables. Is there a way to include these image/s into the reports.
    Thx.

    Easy answer: No, this is not possible. You can't show a PDF inside your report.
    Since you are talking about just images, why do you even store these images as PDF? Why not as JPG or PNG (if you need best image-quality)?
    Using a normal image in a report would be no problem at all.
    Complex answer: Yes, this could be possible with an enormous effort.
    You could write yourself a Java-Bean which reads the BLOB, uses something like "iText" to convert the PDF to a normal image, and then display this image.
    I want to recommend to not use this solution since it introduces a really big complexity into you report where the usual solution of just storing images as images and not PDFs would give you a better result (and way better performance).
    Regards
    Markus

  • Radio Button group with images stored as BLOB files in database

    Hey all!
    I have radio button group, my idea is that radio button's LOV must display images, I mean BLOB files stored in a table.
    How can I do this?

    Hello Ken,
    I asked similar question in the past, and I believe the answer is still the same.
    Select List as an option of a Radio Group
    In your case, I think you can use a select list with added functionality, like "Select List with Branch to Page" or "Select list with Submit", or you can just attach an onChange event (JavaScript) to each select list. The effect should be similar to a radio group – as soon as the user select one item from any of the select lists, you can fire some action, based on the select list value.
    Hope this can help,
    Arie.

  • Image stored in BLOB column crashes report's engine

    Hi,
    I have a report where I display logos stored in a BLOB column on the DB.
    The report is generated as RTF.
    When images have sizes of 624x168 or 423x324 everything is OK. One image, 1221x224, is crashig the report with a dr. Watson error.
    Any idea why?
    The size of the "bad" image file is 38K, and the "good" ones are about 300K.
    Monica

    Sajjad wrote:
    I altered student table to store photoes of students. For this I added STIMG as blob, MIMETYPE,FILENAME,IMAGE_LAST_UPDATE COLUMNS to studentadmitted table. Image stored and displayed in report very nicely. With the following query
    select "ROWID",
    "ST_ID",
    "FIRST_NAME",
    "LAST_NAME",
    "FFIRST_NAME",
    "FLAST_NAME",
    "COURSE_ID",
    "SESSION_ID",
    "CONTACT#" "CONTACT_H",nvl(dbms_lob.getlength(STIMG),0) IMAGE
    from "#OWNER#"."STUDENTADMITTED"
    Images are displayed in column but they have different sizes.Stick to declarative BLOB images as above. They can be resized in reports using CSS. Add a style sheet in the page Inline CSS property:
    td[headers="IMAGE"] img {
      display: block;
      width: 75px;
      border: 1px solid #999;
      padding: 6px;
      background: #f6f6f6;
    }where the <tt>IMAGE</tt> value in the attribute selector is the table header ID of the image column. Setting only one dimension (in this case the width) scales the image with the correct aspect ratio. (The border, padding and background properties are just eye candy...)
    However, if the original images are large then scaling them in the browser this way is a huge waste of bandwidth and produces poorer quality images than creating proper scaled down versions using image tools. Downloading megapixel images and then reducing them to thumbnail size results in pointlessly pushing millions of bytes that will never be seen.
    For improved performance and image quality, and where you require image-specific scaling the best approach is to use the database ORDImage object to produce thumbnail and preview versions automatically. Note that this is not possible in Oracle XE as Multimedia is not included

  • Displaying the image stored in Blob column

    Hi all,
    I'm trying to print the report with an image. I've stored the image in a Blob column and the format of the image is Jpg.
    I'm using the Reports 10g(10.1.2.0.2). When I'm trying to print the report, I'm getting an error Rep-62203. I want to know whether there are any settings which i need to set to display the image item. I mean to say that are there any registry settings.
    Regards,
    Alok Dubey
    Edited by: Alok Dubey on Dec 1, 2008 12:55 PM

    Hi all,
    I'm trying to print the report with an image. I've stored the image in a Blob column and the format of the image is Jpg.
    I'm using the Reports 10g(10.1.2.0.2). When I'm trying to print the report, I'm getting an error Rep-62203. I want to know whether there are any settings which i need to set to display the image item. I mean to say that are there any registry settings.
    Regards,
    Alok Dubey
    Edited by: Alok Dubey on Dec 1, 2008 12:55 PM

  • Display images stored in BLOB in html pages via JSP

    Hello,
    My images are stored in BLOB column of other base than portal.
    in JSP i have to display them in html pages.
    anybody have already did the same thing ?

    teggvb6,
    I believe you should be able to get it to work by doing the grants to the user specified in the DAD (i.e. the user that is logging into Oracle) rather than PUBLIC (someone else may correct me on this?).
    If you're concerned that the procedure could be called by others then I guess you could do some sanity checking within the procedure, for example checking v('APP_USER') or maybe v('SESSION') or perhaps do something clear with the REFERER http header? I haven't thought this through yet but I'm pretty sure you should be able to tie it down a bit more.

  • Images stored in BLOB, any good????

    We are planning on storing images in a Blob data type, any issues with using blobs?
    We will only be storing Tif images (<2 megs each). Anybody have good or bad experience using the Blob data type.
    How easy is it to manipulate the images once they are inside Oracle in a Blob data type. Let say that we plan on moving all the images that are in Oracle to a document imaging tool in about a year, will this be easy to do.
    Any help would be appreciated.
    Guy

    I'm using Oracle 8.1.7

  • Storing a Blob into MySql  from a JTextArea

    I'm using Java 1.4.1, MySql 4.0.12, and MyConnector/J 3.06
    I have an application with a JTextArea and I want to put the contents of the JTextArea into the database stored as a Blob Object. The only reason I'm using Blob is because varchar is limited in lenght by 255 characters.
    The problem I am having is actually creating the Blob Object. I get a null pointer exception no matter what I do.(Even when there is text in the JTextArea) Please take a look at my code and please help me out if you can.
    I'm not sure if I'm using the java Blob correctly as it cannot be instantiated and it's an interface not a class.
    Please give me any suggestions including if there is a better way to doing this without using a Blob object. Thanks in advance.
    // create a new Blob Object, must initialize to something
    Blob tempBlob = null;
    // viewOrdData.notes is the JTextArea
    if (viewOrdData.notes.getText().length() > 0) {
    // THIS IS THE LINE WHERE I GET THE NULL POINTER EXCEPTION
    // I tried initial position both 0 and 1
    tempBlob.setBytes(0,viewOrdData.notes.getText().getBytes())
    stmt.executeUpdate(
    "UPDATE WORKORDER "+
    "SET NOTES = "+tempBlob+" "+ // NOTES is of type Blob
    "WHERE WRKID = "+viewOrdData.workOrderID); // primary key

    Now, Storing a Blob into Database from a JTextArea or any text components becomes easy with the SerialBlob class( javax.sql.rowset.serial.SerialBlob - JDK 1.5).
    For eg..
    For Storing a Blob to Database
    pstmt.setBlob(1,new  SerialBlob(jtextArea.getText().getBytes()));For Retrieving a Blob to JTextArea
    SerialBlob sblob = new SerialBlob(rs.getBlob("FieldName"));
    jTextArea.setText(new String(sblob.getBytes(1, (int)sblob.length())));Hope this serves this problem well.
    Regards,
    R.Amirdha Gopal.

  • Send files stored as blob in mysql as attachment

    Hey guys,thanks for your attention.
    Here is my question:
    Now,in my website I can upload some files into MYSQL DB,and I want to select some of these files as attachment to be sent to customer.
    I know it is very easy if the file is stored as a file in a particular directory,what i need is to get the path of the file and then use a javamail function "attachFile(path)",how can i do it when the file is stored as blob?Is there any javamail function which can be used to manipulate this process?

    Use ByteArrayDataSource, included with JavaMail 1.4 or available in
    the demo directory in earlier versions.

  • Play video stored as BLOB in MySQL

    I would like to use JMF applet to play videos which is stored in mySQL as BLOB. I have finished a solution by playing a video file and store filename as a column in DB. It is easy for programming but hard for future DB management. I want t o improve my design by storing video in DB column. I know it is not hard to do in Oracle. But I have to insist on using mySQL.
    Could anyone has any clue of it? Thanks in advance.

    Use ByteArrayDataSource, included with JavaMail 1.4 or available in
    the demo directory in earlier versions.

  • Displaying images stored in blob columns

    I've seen discussions on how to upload and download blob columns but I want to store a blob in the database and be able to display the blob (which is a jpg) as I would any other <img> on my web page. Instead of having to store the jpg on a file system somewhere, and use the data in the database to formulate a link to the image on the file share, I want to pull it right out of the blob. Does someone have a sample of how to do this? Can I do this?
    Thanks

    Laurence,
    If you uploaded the image via the Application Builder, you can use an image tag like so:
    &lt;img src="#WORKSPACE_IMAGES#my_image.jpg" /&gt;If you followed the upload/download how to, you should be able to reference an image like this:
    &lt;img src="download_my_file?p_file=1232897645" /&gt;Where 1232897645 is the unique ID of the uploaded image. To make referencing images easier, you could write a version of the download_my_file procedure that takes in the name of the image as a parameter.
    Sergio

  • Print image (stored in BLOB in database) on the margin - Oracle Reports 6i

    Hi all,
    I would like to print an image with is in the database as BLOB field.
    I can not retrieve the image with a query in the data model because the column will not have the correct frequency to appear in the margin.
    I can not retrieve the image in trigger reports because I can not store the result in parameter or placeholder columns can not take BLOB.
    How can I do that?
    Thanks.

    Hello,
    I have achieved this by doing so:
    In Data Model:
    Create a query where you select the blob (ideally 1 record). A group will be created.
    In Layout Model:
    Create a repeating frame in the margin, set the source to group based on query where blob is retrieved.
    Insert a field in the repeating frame, set Source to blob field and File Format to Image.
    Regards,
    Avinash

  • Uploading image stored in blob & retrieving to disk

    Hi there...
    Any help will be much appreciated !!!
    I have the following to tasks that I needhelp figuring out:
    I'm using the intermedia WebAgent and interface with
    a jsppage.
    1. I have a table with a field that store images. The field
    isdeclared as blob datatype. My task is to upload images to the
    database from a client side and store it in to server db in this field.
    The examples thatI've got from technet are using fields declared
    as ordImage.
    Can you give me example on how to do this when the db field is a blob ?
    2. On the other problem, I need to retrieve an image from the same field,
    but be able tostore it directly to a local disk at client side.
    Again, the examples I haveis on displaying the image directly on
    the web page.
    Can you give meexample or way how to retrieve the image and store it
    directly to the disk?
    Thanks..
    null

    Some usefull code examples are available @ :
    http://technet.oracle.com/software/tech/java/sqlj_jdbc/software_index.htm
    and
    http://technet.oracle.com/sample_code/tech/java/sqlj_jdbc/files/advanced/LOBSample/LOBSample.java
    hope these help

Maybe you are looking for

  • Where did the link to Mail go!!?

    OK. I am totally confused and lost, and getting very frustrated. I can no longer simply go to Mail via Safari. I go here: http://www.apple.com/ and there is no link to mail. So I click Mac. And it takes me to this: http://www.apple.com/mac/ Still no

  • How to setup WRTSL54GS VPN?

    I'm fairly network literate but I need a walk through for setting up a VPN on WRTSL54GS router and how to confirm settings are working. I talked with Support (in the Phillipines)and advised me to set my DSL modem to bridge mode, done that and Interne

  • Stacked with Error:-30625:ORA-30625: method dispatch on NULL SELF argument

    Hello guys! I'm totally stacked with Error:-30625 trying to execute CLN_CH_EVENT_SUBSCRIPTION_PKG.CREATE_EVENT_SUB procedure. i'm initializing that type object like: WF_EVENT_T.initialize(l_myevent_t); and then fill it with values...and then passing

  • Entry view and general ledger view

    hi gurus, what is the difference between entry view and general ledger view in table level can any one pls help me thanks & regards, balaji.ch

  • Target group changing

    Hello All, I've created TG "My TG" and attached it to a campaign "My campaign". I released campaign and transffered a group to a channel(call list in my case) After that I want to add additional BP to "My TG" and attach this group to the same campaig