2 Replies Latest reply on Oct 28, 2010 12:57 PM by Toadsteraz

    MySQL BLOB to Flex4 Image

    Toadsteraz

      I am having trouble converting a BLOB (MySQL) stored image into a Flex Image.

       

      MySQL Query in coldfusion is as follows (club_images.image is the BLOB):

       

      <cffunction name="GetGeneralData" output="false" access="remote" returntype="Query">

        <cfquery name="qRead" datasource=#website_database#>
         SELECT domain.domain_name, domain.contact_name, domain.contact_number, domain.team_name, domain.gotsoccer, domain.clubwebsite, domain.age_group,
                         club_images.image
         FROM domain, club_images
         WHERE domain = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#domainID#" />
        </cfquery>
       
        <cfreturn qRead>
      </cffunction>

       

      Now when it gets into Flex my results come in as follows:

       

       

      GetGeneralDataResult.token.result[0].image;



       

      GetGeneralDataResult.token.result[0].domain_name;



       

      GetGeneralDataResult.token.result[0].contact_name;

      GetGeneralDataResult.token.result[0].contact_number;

      GetGeneralDataResult.token.result[0].team_name;

      GetGeneralDataResult.token.result[0].gotsoccer;

      GetGeneralDataResult.token.result[0].clubwebsite;

       

      I need to take the Flex returned GetGeneralDataResult.token.result[0].image and convert it so it can be set as the source for an image component. I was told maybe it needs to be converts into a byte array?

       

      My image in Flex is as follows:

       

      <s:Image source=''GetGeneralDAtaResults.token.result[0].image" />

       

      Obviously this doesnt work am in turning to you for help. Anything is appreciated! Thanks -Todd

       

       



       



       

       



        • 1. Re: MySQL BLOB to Flex4 Image
          UbuntuPenguin Level 4

          How is the image being stored ?  Usually , when I need to store an image in a database , I convert it to a byte array, then convert the bytearray to a base64 string. Then, when I need to use the image on the frontend, I reverse the process, string->bytearray->Loader->bitmapdata->image.

          • 2. Re: MySQL BLOB to Flex4 Image
            Toadsteraz Level 1

            First the file is uploaded to my server

             

            I than read the file using coldfusion as follows:

             

            <cffile action = "readbinary" file = "#imagePath##File.ServerFile#" variable="image_blob">

             

            I then store it into a database as follows:

             

            <cfquery name="AddImages" datasource=#website_database#>
                         INSERT INTO club_images (image)
                         VALUES (
                         <cfqueryparam value="#image_blob#" cfsqltype="cf_sql_blob">

                )

            </cfquery>

             

            Then I delete the file off the server since it is now stored in a database

            <cffile action="delete" file="#imagePath##File.ServerFile#"/>

             

            This is how I get it into the database. Not sure what form coldfusion uses to uploade it to the database but I do know the file does get uploaded as I can see the KB amount on that BLOB table.

             

            Todd