473,722 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing jpgs

C G
Dear All,

What's the best way to store jpgs in postgresql to use in a web page?

I tried to use large objects, but how would you extract them from a table to
be viewed in a web-page without having to write them to a scratch file
somewhere first?

Thanks

Colin

_______________ _______________ _______________ _______________ _____
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #1
7 2785
I've found bytea works better for me than large objects.

As far as how to retrieve and display, that depends. What scripting
language are you using?
-----Original Message-----
From: pg************* ****@postgresql .org
[mailto:pg****** ***********@pos tgresql.org]On Behalf Of C G
Sent: Monday, April 05, 2004 12:20 PM
To: pg***********@p ostgresql.org
Subject: [GENERAL] Storing jpgs
Dear All,

What's the best way to store jpgs in postgresql to use in a web page?

I tried to use large objects, but how would you extract them from
a table to
be viewed in a web-page without having to write them to a scratch file
somewhere first?

Thanks

Colin

_______________ _______________ _______________ _______________ _____
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 23 '05 #2
On Mon, 5 Apr 2004, C G wrote:
Dear All,

What's the best way to store jpgs in postgresql to use in a web page?

I tried to use large objects, but how would you extract them from a table to
be viewed in a web-page without having to write them to a scratch file
somewhere first?


There are several ways to skin this cat, and your choice depends largely
on what type of system you'll be deploying.

Will you have more than one front end server? If so, will they be able to
share a network file system mount for the files? Then the preferred
method for many people is to store the jpg in the file system with a path
in the database. If you can't mount the same point from multiple servers
(or don't want to) then you'll need to store them in the database.

However, maybe you want to be able to update multiple jpegs at the same
time in a transaction? then storing them in either a bytea field or
base64 encoded in a text field will work well.

Storing them as base64 or as a path with a file system is likely more
portable than using large objects. Also, you have to dump large
objects seperately, so your backup process may be more complicated than
you want.

As for displaying them whether you store them as bytea, base64 encoded
text, or large objects, most languages will allow you to build and deliver
an image without having to write it to some temporary place.

Here's a simple example from PHPBuilder on doing it with the file path in
the database, and using a directory of files that may lie outside the
documentroot of apache:

http://www.phpbuilder.com/board/show...5#post10497815
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #3
I'm one for using base64 encoded text in a text field. It's easy to
deal with queries, it's easy to deal with spitting out images, and it's
easy to back up. Others do it differently, there are many ways to skin
a cat, and each person who skins cats most likely thinks their way is
best.

Gavin

C G wrote:
Dear All,

What's the best way to store jpgs in postgresql to use in a web page?

I tried to use large objects, but how would you extract them from a
table to be viewed in a web-page without having to write them to a
scratch file somewhere first?

Thanks

Colin

_______________ _______________ _______________ _______________ _____
Stay in touch with absent friends - get MSN Messenger
http://www.msn.co.uk/messenger
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)


---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 23 '05 #4
Would anyone have some example code they could share using libpq to
encode an image into a text field? Right now, I'm converting my image
into a hexadecimal string representation in my SQL statement. I'm sure
there must be a better (faster) way. The hex encodeing/decoding slows
things down for me since my app deals with a lot of images.

On Apr 5, 2004, at 2:03 PM, Gavin M. Roy wrote:
I'm one for using base64 encoded text in a text field. It's easy to
deal with queries, it's easy to deal with spitting out images, and
it's easy to back up. Others do it differently, there are many ways
to skin a cat, and each person who skins cats most likely thinks their
way is best.
Gavin

C G wrote:
Dear All,

What's the best way to store jpgs in postgresql to use in a web page?


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #5
Joe Lester wrote:
Would anyone have some example code they could share using libpq to
encode an image into a text field? Right now, I'm converting my image
into a hexadecimal string representation in my SQL statement. I'm sure
there must be a better (faster) way. The hex encodeing/decoding slows
things down for me since my app deals with a lot of images.


Is this what you're looking for?:
http://www.postgresql.org/docs/7.4/s...C-ESCAPE-BYTEA

I don't have actual numbers to support it, but I would expect that using
Postgres' escape function will be faster since it only escapes what
absolutely must be escaped.

HTH

--
Bill Moran
Potential Technologies
http://www.potentialtech.com
---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 23 '05 #6
What language? Here's a quick example in php that expects a HTML Form
that has a input type=file name=userfile:

<?php

// assumes pg_Connect has been called and the connection is $conn

// check to make sure it's an uploaded file
|if (is_uploaded_fi le(|$_FILES['userfile']['tmp_name']|))
{
// Get Image Information for JPEG Validation
$imgInfo = getimagesize(|$ _FILES['userfile']['tmp_name']);

// Make sure it's a JPEG before moving on
if ( $imgInfo[2] == 2 )
{
|// Read the file in to a variable
$fp = fopen(|$_FILES['userfile']['tmp_name']|, "rb");
$textData = base64_encode(f read($fp,
filesize(|$_FIL ES['userfile']['tmp_name'])));
fclose($fp);

/* Insert into into a table called media with the following schema:
filename varchar(30) not null primary key
mimetype varchar(30) not null default 'image/jpeg'
filedata text
*/
pg_Query($conn, "INSERT INTO media VALUES('" .
$_FILES['userfile']['name'] . "','image/jpeg', '$textData');
} else {
echo "Uploaded file isn't a valid JPEG.\n";
}
} else {
echo "Invalid file upload.\n";
}
}
|
?>
|
And to send it:

<?php
// assumes a GET variable called image
(http://yoursite.com/displayImage.php?image=picture.jpg and
// pg_Connect already called with $conn as connection

$result = pg_Query($conn, "SELECT mimetype, filedata FROM media WHERE
filename = '" . $_GET['image'] . "';");
if ( pg_NumRows($res ult) > 0 )
{
$data = pg_Fetch_Object ($result, 0);
Header("Content-type: $data->mimetype");
echo base64_decode($ data->filedata);
exit();
} else {
echo "404: File Not Found.";
}
?>

Hope this helps, I've not tested it but it should work ok and at best it
illustrates the principles.

Gavin
Joe Lester wrote:
Would anyone have some example code they could share using libpq to
encode an image into a text field? Right now, I'm converting my image
into a hexadecimal string representation in my SQL statement. I'm sure
there must be a better (faster) way. The hex encodeing/decoding slows
things down for me since my app deals with a lot of images.

On Apr 5, 2004, at 2:03 PM, Gavin M. Roy wrote:
I'm one for using base64 encoded text in a text field. It's easy to
deal with queries, it's easy to deal with spitting out images, and
it's easy to back up. Others do it differently, there are many ways
to skin a cat, and each person who skins cats most likely thinks
their way is best.
Gavin

C G wrote:
Dear All,

What's the best way to store jpgs in postgresql to use in a web page?


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 23 '05 #7
Rod K wrote:
I've found bytea works better for me than large objects.


Speaking of BYTEA, what is the recommended maximum sizes for data to be
put in there. I've played with megabytes-sized BYTEA and the memory
requirement is pretty huge... Is it possible for BYTEA to be efficient
and supporting chunk processing in the future? Is BYTEA and TEXT the
future of all lobs?

--
dave
---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #8

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

Similar topics

1
2469
by: Waguih Boctor | last post by:
Hi, I have a number of ASP pages where some JPGs and GIFs are displaying in the browser and some are not. I have included an excerpt from the HTML below. In this example, the gif file at the bottom of the example is displaying (I have others that don't), while the jpg file at the top isn't. Both files are in the same folder (visible bith physical in WE and virtual in CM) as the asp file itself. WHen not displaying, it displays instead...
4
1677
by: walterbyrd | last post by:
Let's suppose I have dozens, or hundreds of JPGs. I want to put them in photo album sort of format. With thumbnail and all. Do I have to specically spell out the full name of each file? Or is there a way to create a script that will pick up the next JPG, and put it in the next location?
1
1405
by: Ecohouse | last post by:
I have created a MS Access Project linking to a SQL database. I created a table that I want to hold jpgs in. The actual field I created is a datatype of image. I created a form in Access. When I click on the picture frame I right click to insert an object. I then find the jpg and insert it. But the picture doesn't show on the form. When I look at the table that field just says Package. So I wanted to know what I need to do to get...
3
1061
by: David A. Osborn | last post by:
I'm looking to write a program that can scale down JPGs to 640x480 resolution. I know that XP has a feature that when you right click on a JPG and select send to a recepient it prompts you about resizing the image, is there any way to call this function or some other function I can use?
5
2119
by: Garry Jones | last post by:
I need to create a page with a password where I show photos. How do I stop people from accessing the jpgs directly without going through the password function. I am using Windows XP and have a website which supports Mysql and php. The end result should be a page where the user can type in a password and access a few pages of thumbnails which can be clicked for enlargements. Garry Jones
13
3693
by: Rhino | last post by:
Is it possible to store Java objects in DB2 V8.2 for Windows/Unix/Linux via JDBC? Specifically, if I have a 4-dimensional boolean array, i.e. boolean, can I store it directly in a column of a DB2 table? If so, how do I do it? It would be VERY convenient if I could store this boolean array directly in a column of a DB2 table but I'm not at all clear on whether this is possible, even after reading the documentation in the Information...
27
2271
by: Chris Tomlinson | last post by:
Hi, is there any way to specify the sequence in which images load on a web page? More specifically, here is what we need to achieve: Image1 starts loading first and the browser does not continue through the HTML until Image1 has loaded COMPLETELY. When Image1 is done, Image2 BEGINS loading. When Image2 is 100% done, only then does Image 3 begin... and so on...
2
1304
by: VivekR | last post by:
Hi All Please help me out with this thing in javascript. I am dumb in the world of JS/Html/... I have a url, say www.someurl.com. It has a list of jpgs that can accessed as www.something.com/one.jpg or www..../two.jpg etc. Now i need to get the list of the jpgs and then display it on a web page one by one, triggered by a timer. I have to do this using javascript.
8
1478
by: J. Frank Parnell | last post by:
Hi there, I got this directory tree listing function somewhere, it works great, but I want it to only list directories that do have one or more .jpgs inside. I tried getting a list of each dir's contents and doing if count($dir) 0 But something not working out for me. <?php // $path : path to browse
0
8739
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
9236
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
9154
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
9088
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
8051
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...
0
5995
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
4502
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
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2601
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.