[Gambas-user] Q:how to save a file.png into Postgresql
Benoit Minisini
gambas at ...1...
Sun Aug 31 09:34:47 CEST 2008
On dimanche 31 août 2008, richard terry wrote:
> snip..
>
> > Did you look at the "PictureDatabase" example? It stores images files
> > from disk into a database, and retrieves them.
>
> Thanks, yes I've done that overnight since your suggestion, and now have
> this problem:
>
> My gambas code goes something like this and I've selected the png file to
> load which has been passed to this routine as ImagePath.
>
> Public sub Save_Image(ImagePath as string)
>
> Dim img As Image
> Dim pictureData As String
> Dim sql As String
>
> img = Image.Load(ImagePath) ' Save temp image as png file
> tempFile = Temp() & ".png"
> img.Save(tempFile)
>
>
> pictureData = File.Load(tempFile) 'reload as a string
>
>
> At this point the pictureData string seems to be ok.
>
> I Then tried writing to the database:
>
> sql = "insert into temp_image(piccie)"
> "values($$"
> sql = sql & pictureData & "$$)"
>
> and got back this message:
>
> Query failed:ERROR: invalid byte sequence for encoding "UTF8":0x89 HINT:
> This error can also happen if the byte sequence does not match the encoding
> expected by the server, which is controlled by "client_encoding"
>
> Spent a couple of hours trawling the postgres help and looking up
> client-encoding, pg_types etc etc, but with my limited brain power I got
> nowhere
>
> Any idea's?
>
>
> Regards
>
> Richard
>
1) Check that piccie is actually a Blob field (did you create your database
with the database manager?)
2) Do not forge your query yourself. Use the substitution parameters of the
Exec command:
DB.Exec("insert into temp_image(piccie) values(&1)", pictureData)
Regards,
--
Benoit Minisini
More information about the User
mailing list