473,695 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET mySQL BLOB

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 _connectionStri ng = ConfigurationMa nager.Connectio nStrings[ "DB"
].ToString(); string imageQuery = "SELECT fullsize AS image_data
FROM table WHERE id ='A1'";

OdbcConnection connection = new OdbcConnection(
ConfigurationMa nager,Connectio nStrings["DB"].ToString() );

OdbcCommand cmd = new OdbcCommand( imageQuery, connection );

DataSet dsImage = new DataSet();

Response.Conten tType = "image/jpeg";
Response.Binary Write( ( 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_obj ect(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

Aug 27 '06 #1
4 3792
KJ
I believe you need a little more in the headers. For example (code not
tested):

Response.Clear( );
Response.Conten tType = "image/jpeg";
Response.Append Header("Content-Length", ( Byte[] )dsImage.Tables[ 0
].Rows[ 0 ]["image_data " ].Length.ToStrin g());
Response.Append Header("Content-Disposition","i nline;filename= AName.jpeg);
Response.Binary Write(( Byte[] )dsImage.Tables[ 0 ].Rows[ 0
]["image_data " ]);
Response.End();

cu**********@gm ail.com wrote:
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 _connectionStri ng = ConfigurationMa nager.Connectio nStrings[ "DB"
].ToString(); string imageQuery = "SELECT fullsize AS image_data
FROM table WHERE id ='A1'";

OdbcConnection connection = new OdbcConnection(
ConfigurationMa nager,Connectio nStrings["DB"].ToString() );

OdbcCommand cmd = new OdbcCommand( imageQuery, connection );

DataSet dsImage = new DataSet();

Response.Conten tType = "image/jpeg";
Response.Binary Write( ( 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_obj ect(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
Aug 28 '06 #2
Thank you for the information. Unfortunately it has yeilded the same
results.

Regards,

Cuyler Jones
KJ wrote:
I believe you need a little more in the headers. For example (code not
tested):

Response.Clear( );
Response.Conten tType = "image/jpeg";
Response.Append Header("Content-Length", ( Byte[] )dsImage.Tables[ 0
].Rows[ 0 ]["image_data " ].Length.ToStrin g());
Response.Append Header("Content-Disposition","i nline;filename= AName.jpeg);
Response.Binary Write(( Byte[] )dsImage.Tables[ 0 ].Rows[ 0
]["image_data " ]);
Response.End();

cu**********@gm ail.com wrote:
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 _connectionStri ng = ConfigurationMa nager.Connectio nStrings[ "DB"
].ToString(); string imageQuery = "SELECT fullsize AS image_data
FROM table WHERE id ='A1'";

OdbcConnection connection = new OdbcConnection(
ConfigurationMa nager,Connectio nStrings["DB"].ToString() );

OdbcCommand cmd = new OdbcCommand( imageQuery, connection );

DataSet dsImage = new DataSet();

Response.Conten tType = "image/jpeg";
Response.Binary Write( ( 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_obj ect(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
Aug 28 '06 #3
Any insight (beyond the obvious (don't use Blobs!) :-) ) would be MOST
appreciated!
First off then, you might want to use the mysql connector.
Which is bound to perform a lot better then ODBC

This is a help segment talking about blobs:

http://dev.mysql.com/doc/refman/5.0/...sing-blob.html

Release version:
http://dev.mysql.com/downloads/connector/net/1.0.html
Aug 28 '06 #4
Mischa,

Thank you for your input. I tried the mySQL connector and followed the
example, however I ended up in the same spot.

The line: FileSize = myData.GetUInt3 2(myData.GetOrd inal("file_size "));
from the example, throws and exception. (Cannot convert type
System.Byte[] to System.IConvert able).

One of the problems is that I do not have the size of the file stored
in the database, so I had to get it manually:

string test = myData.GetStrin g(0);
FileSize = Convert.ToUInt3 2( test.Length );
....

Addtionally, the line: myData.GetBytes (myData.GetOrdi nal("file"), 0,
rawData, 0, FileSize); from the example requires a cast of "FileSize"
from UInt32 to int, which is a potential issue.

I am beginning to think that what I am trying to do is impossible with
the C#2.0 / mySQL combination, or the problem is beyond my current
skill level, as I have exhausted every resource that I can think of.

Regards,

Cuyler Jones
Mischa Kroon wrote:
Any insight (beyond the obvious (don't use Blobs!) :-) ) would be MOST
appreciated!

First off then, you might want to use the mysql connector.
Which is bound to perform a lot better then ODBC

This is a help segment talking about blobs:

http://dev.mysql.com/doc/refman/5.0/...sing-blob.html

Release version:
http://dev.mysql.com/downloads/connector/net/1.0.html
Aug 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7430
by: Sugapablo | last post by:
Is there any PHP function that will allow me to determine the MIME type of a blob stored in MySQL? Specifically, if I'm storing an image as a blob in MySQL, is there any PHP function that can determine whether it's a gif, jpeg, png, etc? -- http://www.sugapablo.com <--music ] http://www.sugapablo.net <--personal ]
1
3359
by: Kirby Urner | last post by:
I've been testing the Cookbook example 8.6 (2002 edition) re using cPickle to insert and retrieve BLOBs from mySQL, using Python's MySQLdb module. When I try to cPickle.loads(blob), I get an error telling me that loads wants a string, not type array.array. So I go cPickle.loads(blob.tostring()) instead and it works. My question is: has something changed in the Python API since this example was written?
0
1282
by: Dyego Souza do Carmo | last post by:
Hi, I'd found a bug when I'd tried to use blob fields and innoDb. To see the bug, do the follow: *) Create a database. *) Import the dump file that is attached to this e-mail. (cfgimpressao.dump) *) Use the following commands:
7
11478
by: sime | last post by:
Hi, I have a blob field in a mysql database table. I want to copy a blob from one record to another. I am having trouble transferring the data via a php variable. Maybe I need to addslashes or convert to Hex or something. I've tried a few things but can't quite get it. Here is simplified code. mysql_select_db($dbname, $connection);
2
8998
by: pmz | last post by:
Dear Group, I'm connecting in C# with remote (BSD) MySQL server with ODBC Driver, and I'm trying to find the best sollution in such problem: As I've read on MySQL manual, they have suggested table design including the BLOB-Fieldtype size in UInt64, where they've stored, while inserting, the size of inserted BLOB data. But in the matter of fact, I'm interested if it's necessary to include in table this integer field? Is there any way...
7
10150
by: greywire | last post by:
So I need to load lots of data into my database. So I discover LOAD DATA INFILE. Great! This little gem loads my CSV in blazing times (compared to parsing the file and doing INSERT for each row). Its still slow on large files, but just barely acceptable. Only one problem. It truncates fields to 256 characters, even on a text field.
2
6517
by: Vinciz | last post by:
hi guys... im new in java and i would love to learn some of these... basically i got a sample code to retrieve the blob from the mysql. however, i dont really know what to do with these retrieved byte/binary data as i got no idea on how to save them in our pc. For this situation, what i need to do is give the byte/binary data an extension (retrieved from another field in the table) in order to revert back to the original data i had in the...
0
2126
by: dimitri pater | last post by:
Hi, I am trying to insert an image, which is stored as a blob in MySQL, into a table using Reportlab. I have tried this: from StringIO import StringIO cfoto = StringIO(result) # where result is the 'blob' cfoto.seek(0) foto=cfoto.getvalue
6
38507
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
6
5094
by: Keith Hughitt | last post by:
Hi all, I've run into a strange error while trying to store some PNG images in a MySQL database using MySQLdb. When I try to insert smaller images (< 64kb or so) everything seems to work fine. When I start trying to insert larger images (~150kb), however, the images get corrupted along the way. The result is that only part of the image, e.g. the top 30% of the image, is stored in the database, and the rest is simply transparent.
0
8586
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9137
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9004
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4351
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1986
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.