Re: Insert image into bytea question

From: Chris Campbell <ccampbell(at)cascadeds(dot)com>
To: George Roberge <groberge(at)andforthelamb(dot)org>, "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Insert image into bytea question
Date: 2014-05-01 13:42:40
Message-ID: 453A24085F801842AEA8D0B6B269065D042ACDE30AE7@HDMC.cds.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>From: pgsql-novice-owner(at)postgresql(dot)org [mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of George Roberge
>Sent: Wednesday, April 30, 2014 5:39 PM
>To: pgsql-novice(at)postgresql(dot)org
>Subject: [NOVICE] Insert image into bytea question

>Greetings, all.

>This might be a stupid question, but I have not found one good post or article on the syntax for inserting an image into a PostgreSQL table bytea field on the Internet.

>I am currently learning version 9.1, which I had read should work pretty well for inserting and retrieving images in the bytea format, but i don't know how. I have seen examples of the bytea_import command (which I couldn't get to work), and other posts that state that the image must be encoded using a "SELECT encode(XXXX)" statement in the query. I had originally intended to store the location of the image into a field in the database and just pull that reference from the table, and was hopeful when I saw that PostgreSQL can handle storing images directly, and that it may be even be the preferred method in some cases.

>I have been looking online for a couple of hours and have left the Net about as confused as when I started! I think that some of the reason is that this appears to be a newer method of doing things, and I have been reading older information.

I wrote a couple functions to convert the byte data to and from a string in VS 2010 .Net and then store it to a text field in the table. I’m sure there is a more “proper” way to do this but like you, I had a hard time finding any useful examples.

Imports System.Text.RegularExpressions
*
*
*
Public Function ToBase64(ByVal data() As Byte) As String
If data Is Nothing Then Throw New ArgumentNullException("data")
Return Convert.ToBase64String(data)
End Function

Public Function FromBase64(ByVal base64 As String) As Byte()
If base64 Is Nothing Then Throw New ArgumentNullException("base64")
Return Convert.FromBase64String(base64)
End Function

My issue was that I retrieve and store data in XML so I must always deal with text.

Regards,

Chris

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message George Roberge 2014-05-02 01:24:52 Re: Insert image into bytea question
Previous Message David G Johnston 2014-05-01 01:31:10 Re: Insert image into bytea question