Save and load jpg in a PostgreSQL database

Started by lfmartinelliover 15 years ago6 messagesgeneral
Jump to latest
#1lfmartinelli
luis.fernando.martinelli@gmail.com

Hi,

My name is Fernando, i work with C# and PostgreSQL. I need save a jpg in a
PostgreSQL table.
How do i this? I read in a forum to use this to save in database:

INSERT INTO table (image) VALUES (pg_escape_bytea(image.jpg))

Don't i need convert image file to binary before save in a database?
How get i this image to a variable using c#?

Please help me!

Thanks.
--
View this message in context: http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3249969.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#2Dmitriy Igrishin
dmitigr@gmail.com
In reply to: lfmartinelli (#1)
Re: Save and load jpg in a PostgreSQL database

Hey Fernando,

If you need to store binary data in a table you should use bytea data type.
Than, in case of libpq:
If you want to transmit binary data from client to server in text format you
must prepare (escape) it for including into you SQL command (e.g., INSERT).
If you can transmit the data from client to server in binary format you
don't
need escape you binary data, but you must tell libpq (or the library you
use)
that you transmission will be in a binary format.

What library do you use to work with PostgreSQL ?

2010/11/4 lfmartinelli <luis.fernando.martinelli@gmail.com>

Hi,

My name is Fernando, i work with C# and PostgreSQL. I need save a jpg in a
PostgreSQL table.
How do i this? I read in a forum to use this to save in database:

INSERT INTO table (image) VALUES (pg_escape_bytea(image.jpg))

Don't i need convert image file to binary before save in a database?
How get i this image to a variable using c#?

Please help me!

Thanks.
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3249969.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
// Dmitriy.

#3lfmartinelli
luis.fernando.martinelli@gmail.com
In reply to: Dmitriy Igrishin (#2)
Re: Save and load jpg in a PostgreSQL database

Hey Dmitriy,

I'm using Visual Studio 2010 system.data.odbc becouse this worked good
and i tested psqlodbc lib to .Net, but i don't find any advantage to use
this.
In a Brazilian forum, i read a post and it was written:

-" Just use this line: INSERT INTO table (image) VALUES
(pg_escape_bytea(image.jpg))".

Changing "image.jpg" to my image file, the PostgreSQL already convert
this and save in a database.
Is this true? And how can i load this to imageBox in my system? Which
type must be declared my variable?

Thanks to your help.

Em 04/11/2010 15:40, Dmitriy Igrishin [via PostgreSQL] escreveu:

Hey Fernando,

If you need to store binary data in a table you should use bytea data
type.
Than, in case of libpq:
If you want to transmit binary data from client to server in text
format you
must prepare (escape) it for including into you SQL command (e.g.,
INSERT).
If you can transmit the data from client to server in binary format
you don't
need escape you binary data, but you must tell libpq (or the library
you use)
that you transmission will be in a binary format.

What library do you use to work with PostgreSQL ?

2010/11/4 lfmartinelli <[hidden email]
</user/SendEmail.jtp?type=node&node=3250498&i=0>>

Hi,

My name is Fernando, i work with C# and PostgreSQL. I need save a
jpg in a
PostgreSQL table.
How do i this? I read in a forum to use this to save in database:

INSERT INTO table (image) VALUES (pg_escape_bytea(image.jpg))

Don't i need convert image file to binary before save in a database?
How get i this image to a variable using c#?

Please help me!

Thanks.
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3249969.html
<http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3249969.html?by-user=t&gt;
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list ([hidden email]
</user/SendEmail.jtp?type=node&node=3250498&i=1>)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
// Dmitriy.

------------------------------------------------------------------------
View message @
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3250498.html

To unsubscribe from Save and load jpg in a PostgreSQL database, click
here
<http://postgresql.1045698.n5.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&amp;node=3249969&amp;code=bHVpcy5mZXJuYW5kby5tYXJ0aW5lbGxpQGdtYWlsLmNvbXwzMjQ5OTY5fDE5NTY2MjIzNDg=&gt;.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3252295.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

#4Elford,Andrew [Ontario]
Andrew.Elford@ec.gc.ca
In reply to: lfmartinelli (#3)
Re: Save and load jpg in a PostgreSQL database

I use Large Objects for my images (and any binary file type). there's
section in the PostgreSQL docs on it. In php, I need to get the oid
from pg_lo_import($conn, $imagefile) then manage an index table that
has a list of my images:

INSERT INTO images (filename, mimetype, datetime, image) VALUES
('$filename','$mimetype', $imagedate, $oid);

(I know you aren't useing php; this is just an example)

I can't help with your imageBox question :(

________________________________

From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of lfmartinelli
Sent: 2010 November 5 2:46 PM
To: pgsql-general@postgresql.org
Subject: Re: [GENERAL] Save and load jpg in a PostgreSQL database

Hey Dmitriy,

I'm using Visual Studio 2010 system.data.odbc becouse this worked good
and i tested psqlodbc lib to .Net, but i don't find any advantage to use
this.
In a Brazilian forum, i read a post and it was written:

-" Just use this line: INSERT INTO table (image) VALUES
(pg_escape_bytea(image.jpg))".

Changing "image.jpg" to my image file, the PostgreSQL already convert
this and save in a database.
Is this true? And how can i load this to imageBox in my system? Which
type must be declared my variable?

Thanks to your help.

Em 04/11/2010 15:40, Dmitriy Igrishin [via PostgreSQL] escreveu:

Hey Fernando,

If you need to store binary data in a table you should use bytea
data type.
Than, in case of libpq:
If you want to transmit binary data from client to server in
text format you
must prepare (escape) it for including into you SQL command
(e.g., INSERT).
If you can transmit the data from client to server in binary
format you don't
need escape you binary data, but you must tell libpq (or the
library you use)
that you transmission will be in a binary format.

What library do you use to work with PostgreSQL ?

2010/11/4 lfmartinelli <[hidden email]>

Hi,

My name is Fernando, i work with C# and PostgreSQL. I
need save a jpg in a
PostgreSQL table.
How do i this? I read in a forum to use this to save in
database:

INSERT INTO table (image) VALUES
(pg_escape_bytea(image.jpg))

Don't i need convert image file to binary before save in
a database?
How get i this image to a variable using c#?

Please help me!

Thanks.
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQ
L-database-tp3249969p3249969.html
<http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreS
QL-database-tp3249969p3249969.html?by-user=t&by-user=t>
Sent from the PostgreSQL - general mailing list archive
at Nabble.com.

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
// Dmitriy.

________________________________

View message @
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQ
L-database-tp3249969p3250498.html
<http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreS
QL-database-tp3249969p3250498.html?by-user=t>
To unsubscribe from Save and load jpg in a PostgreSQL database,
click here
<http://postgresql.1045698.n5.nabble.com/template/TplServlet.jtp?tpl=uns
ubscribe_by_code&node=3249969&code=bHVpcy5mZXJuYW5kby5tYXJ0aW5lbGxpQGdtY
WlsLmNvbXwzMjQ5OTY5fDE5NTY2MjIzNDg=&by-user=t> .

________________________________

View this message in context: Re: Save and load jpg in a PostgreSQL
database
<http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreS
QL-database-tp3249969p3252295.html>
Sent from the PostgreSQL - general mailing list archive
<http://postgresql.1045698.n5.nabble.com/PostgreSQL-general-f1843780.htm
l> at Nabble.com.

#5Dmitriy Igrishin
dmitigr@gmail.com
In reply to: lfmartinelli (#3)
Re: Save and load jpg in a PostgreSQL database

Hey Fernando,

There is no pg_escape_bytea() in PostgreSQL. It seem like a function of some
PL, like PHP or Tcl... So, the command that you found on a forum is
incorrect.
As I understand, you want to upload a file from your (client) filesystem to
the
PostgreSQL database (server) and store it in the column of type bytea of
some
table, right?
First, you need to read the file from your file system.
Next, if you want to transmit it as is (i.e. in a binary format), you don't
need any
escaping. But not all client libraries supports transmission in binary
format. If you
need (want) to transmit you binary data in the text format, you must escape
it
(e.g. by using pg_escape_bytea() or another function of library you use).
Please,
follow the documentation of the library / framework that you are use.

2010/11/5 lfmartinelli <luis.fernando.martinelli@gmail.com>

Hey Dmitriy,

I'm using Visual Studio 2010 system.data.odbc becouse this worked good and
i tested psqlodbc lib to .Net, but i don't find any advantage to use this.
In a Brazilian forum, i read a post and it was written:

-" Just use this line: INSERT INTO table (image) VALUES (pg_escape_bytea(
image.jpg))".

Changing "image.jpg" to my image file, the PostgreSQL already convert this
and save in a database.
Is this true? And how can i load this to imageBox in my system? Which type
must be declared my variable?

Thanks to your help.

Em 04/11/2010 15:40, Dmitriy Igrishin [via PostgreSQL] escreveu:

Hey Fernando,

If you need to store binary data in a table you should use bytea data type.
Than, in case of libpq:
If you want to transmit binary data from client to server in text format
you
must prepare (escape) it for including into you SQL command (e.g., INSERT).
If you can transmit the data from client to server in binary format you
don't
need escape you binary data, but you must tell libpq (or the library you
use)
that you transmission will be in a binary format.

What library do you use to work with PostgreSQL ?

2010/11/4 lfmartinelli <[hidden email]<http://user/SendEmail.jtp?type=node&amp;node=3250498&amp;i=0&amp;by-user=t&gt;

Hi,

My name is Fernando, i work with C# and PostgreSQL. I need save a jpg in a
PostgreSQL table.
How do i this? I read in a forum to use this to save in database:

INSERT INTO table (image) VALUES (pg_escape_bytea(image.jpg))

Don't i need convert image file to binary before save in a database?
How get i this image to a variable using c#?

Please help me!

Thanks.
--
View this message in context:
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3249969.html&lt;http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3249969.html?by-user=t&amp;by-user=t&gt;
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

--
Sent via pgsql-general mailing list ([hidden email]<http://user/SendEmail.jtp?type=node&amp;node=3250498&amp;i=1&amp;by-user=t&gt;
)

To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
// Dmitriy.

------------------------------
View message @
http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3250498.html&lt;http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3250498.html?by-user=t&gt;
To unsubscribe from Save and load jpg in a PostgreSQL database, click here<http://postgresql.1045698.n5.nabble.com/template/TplServlet.jtp?tpl=unsubscribe_by_code&amp;node=3249969&amp;code=bHVpcy5mZXJuYW5kby5tYXJ0aW5lbGxpQGdtYWlsLmNvbXwzMjQ5OTY5fDE5NTY2MjIzNDg=&amp;by-user=t&gt;.

------------------------------
View this message in context: Re: Save and load jpg in a PostgreSQL
database<http://postgresql.1045698.n5.nabble.com/Save-and-load-jpg-in-a-PostgreSQL-database-tp3249969p3252295.html&gt;

Sent from the PostgreSQL - general mailing list archive<http://postgresql.1045698.n5.nabble.com/PostgreSQL-general-f1843780.html&gt;at Nabble.com.

--
// Dmitriy.

#6bonave
bonave@live.co.uk
In reply to: lfmartinelli (#1)
Re: Save and load jpg in a PostgreSQL database