C
cuyler.jones
Hello --
I'm having a heck of a time grabbing a blob ( a jpeg image) from a
mySQL database and displaying it on a page.
I am able to connect to the database and retrieve the data, however
when the page loads, it just spews the binary garbage rather than
displaying the image.
Here's the code:
string _connectionString = ConfigurationManager.ConnectionStrings[ "DB"
].ToString(); string imageQuery = "SELECT fullsize AS image_data
FROM table WHERE id ='A1'";
OdbcConnection connection = new OdbcConnection(
ConfigurationManager,ConnectionStrings["DB"].ToString() );
OdbcCommand cmd = new OdbcCommand( imageQuery, connection );
DataSet dsImage = new DataSet();
Response.ContentType = "image/jpeg";
Response.BinaryWrite( ( Byte[] )dsImage.Tables[ 0 ].Rows[ 0 ][
"image_data" ] );
It appears to be a problem with Base64Decoding... but I'm stumped. I'm
basically trying to replicate some PHP code:
<?
$image_data = (isset($_GET['swatchthumb'])) ? 'select swatchthumb as
image_data from birdie_product_model where uid = "'.$_GET['uid'].'"' :
'select fullsize as image_data from birdie_product_model where uid =
"'.$_GET['uid'].'"';
$image_data = mysql_fetch_object(mysql_query($image_data));
header("Content-type: image/jpeg");
echo base64_decode($image_data->image_data);
?>
Any insight (beyond the obvious (don't use Blobs!)
) would be MOST
appreciated!
Regards,
Cuyler Jones
I'm having a heck of a time grabbing a blob ( a jpeg image) from a
mySQL database and displaying it on a page.
I am able to connect to the database and retrieve the data, however
when the page loads, it just spews the binary garbage rather than
displaying the image.
Here's the code:
string _connectionString = ConfigurationManager.ConnectionStrings[ "DB"
].ToString(); string imageQuery = "SELECT fullsize AS image_data
FROM table WHERE id ='A1'";
OdbcConnection connection = new OdbcConnection(
ConfigurationManager,ConnectionStrings["DB"].ToString() );
OdbcCommand cmd = new OdbcCommand( imageQuery, connection );
DataSet dsImage = new DataSet();
Response.ContentType = "image/jpeg";
Response.BinaryWrite( ( Byte[] )dsImage.Tables[ 0 ].Rows[ 0 ][
"image_data" ] );
It appears to be a problem with Base64Decoding... but I'm stumped. I'm
basically trying to replicate some PHP code:
<?
$image_data = (isset($_GET['swatchthumb'])) ? 'select swatchthumb as
image_data from birdie_product_model where uid = "'.$_GET['uid'].'"' :
'select fullsize as image_data from birdie_product_model where uid =
"'.$_GET['uid'].'"';
$image_data = mysql_fetch_object(mysql_query($image_data));
header("Content-type: image/jpeg");
echo base64_decode($image_data->image_data);
?>
Any insight (beyond the obvious (don't use Blobs!)
![Smile :-) :-)](/styles/default/custom/smilies/smile.gif)
appreciated!
Regards,
Cuyler Jones