473,714 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MYSQL and use of blobs

It is the first time that I use blobs in mysql.
Please help me out here.....

Using MSSQLdb and python 2.3.4 I was surprised to see how my information was stored in the blob.
My goal is to store JPG images in the blob. Well, it stores it but as a string of bytes:
'x0dx0fxffxa3.. ....'

So, when reading back that information into my python environment, it seems that I need to translate the value back to the original binary format?

Sniffed for an hour in the asciibin, binhex and other modules...

Somebody with experience to help me out here?
Is there something fundamentally that I do wrong here? In storage, retreiving...

Any help would be very appreciated.
Vincent
Jul 18 '05 #1
1 3657
On Thu, 29 Jul 2004 08:48:28 -0500, Raaijmakers, Vincent (GE
Infrastructure) <Vi************ *****@ge.com> wrote:
It is the first time that I use blobs in mysql Please help me out .
here.... .

Using MSSQLdb and python 2.3.4 I was surprised to see how my
information was stored in the blob. My goal is to store JPG
images in the blob. Well, it stores it but as a string of bytes:
'x0dx0fxffxa3.. ....'

So, when reading back that information into my python environment, it
seems that I need to translate the value back to the original binary
format?

Sniffed for an hour in the asciibin, binhex and other modules...

Somebody with experience to help me out here? Is there something
fundamentally that I do wrong here? In storage, retreiving...

Any help would be very appreciated. Vincent

I didn't have to do anything more fancy than read the information
from the database and write it as a binary file.

SQL table:

create table if not exists audioImage(id int auto_increment primary key,
problemID int, realName varchar(250), shortName varchar(250), data
longblob
Storing the images/audio files:
fileData = open(fileName, 'rb').read()
fileData = zlib.compress(f ileData,9)
fileData = db.escape_strin g(fileData)
query = "insert into audioImage(prob lemID, data,
shortName) values(%d, '%s', '%s')" % (problemID,
fileData, file)

Retrieving the stored images or audio files:
self.db.execute ('select shortName,data from audioImage where id=%d' % int(id))
result = self.db.getAll( )
fileName = result[0][0]
retResult = result[0][0]
realData = zlib.decompress (result[0][1])
open(fileName,' wb').write(real Data)
This deposits the audio/image files in the current directory where
the program picks them up and uses them. There wasn't anything special
to do, other than retrieving and decompressing the data.
--Mark Hertel
Jul 18 '05 #2

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

Similar topics

1
3361
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
1216
by: Dyego Souza do Carmo | last post by:
Hi, I would like to know if you could fix the bug I reported to you some days ago. The error is: "ERROR 1030: Got error 139 from table handler" after running an update command using several blobs. Now I am using mySql 4.0.15 and Linux. If you try to do the same with mySql 4.0.14, the record that is updated is simple deleted.
4
4486
by: Amadeus | last post by:
Hello Everybody! I have a problem with MySQL servers running RedHat 9 (smp kernel 2.4.20) on Intel and MySQL server 4.0.14 (problem also appears on binary distr 4.0.15 and on 4.0.15 I bilt myself from source). I have few big tables with BLOBS and regular table 4.2 and 2.7 Gb respectively, plust several smaller tables. Every time I run query against this tables MySQL uses all available memory on server (I have 3Gb RAM on server) and it...
7
6946
by: Howard Lowndes | last post by:
My situation is that I am interacting PHP 4.1.2 to PostgreSQL 7.2.2 I have no difficulty inserting and managing BLOBs into the Large Object system table, and I have a user table called images which maintains the relationship between the BLOB loid and the identity that relates to it in my user tables. So far so good. When I RTFM obout psql it refers to the \lo_import, \lo_list, \lo_export and \lo_unlink functions.
10
7398
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't recommend storing the image to the filesystem and only keeping a pointer to that in the table. I want to dump the image to a table. My code dumps the data into the table, however, I get the following error when trying to view the image "the image ......
2
2819
by: Jerry LeVan | last post by:
Hi, I am just getting into large objects and bytea "stuff". I created a small db called pictures and loaded some large objects and then tried to do a restore. Here is how I got the dump. pg_dump -Fc -b pictures > /Users/jerry/desktop/db.comp
4
3796
by: cuyler.jones | last post by:
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:
10
13405
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without a problem. I am using chunk_split(data) and the base64_encode and base64_decode on the files. I do a select from the database, and then echo the image (with header(Content Type: image/jpeg) and the decoded image displays fine. Yes, I have...
3
5388
by: Taras_96 | last post by:
Hi everyone, I'm having a bit of trouble understanding the purpose of escaping nulls, and the use of addcslashes. Firstly, the manual states that: "Strictly speaking, MySQL requires only that backslash and the quote character used to quote the string in the query be escaped. This function quotes the other characters to make them easier to read in
0
8704
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
9171
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...
1
9071
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,...
0
9010
tracyyun
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...
0
5945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4462
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
4717
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.