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 4 3801
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 ]
|
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?
|
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:
|
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);
|
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...
| |
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.
|
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...
|
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
|
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
|
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.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |