Hi richard

> 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"

Hope you defined your database field as byta for blob.
Then you have to mask out a lot of byte codes in your picture data.

I did it like this:

PUBLIC SUB SavePic_Click()
  DIM hFile AS Stream
  DIM buffer AS Byte
  DIM picText AS String

  OPEN NameOfPic FOR INPUT AS #hFile
    WHILE NOT Eof(hFile)
      READ #hFile, buffer, lof(hFile)
      IF buffer < 32 OR buffer > 126 THEN
        picText = picText & "\\\\" & Coct(buffer)
      ELSE
        SELECT buffer
          CASE 92    ' mask  "|" char
            picText = picText & "\\\\134"
          CASE 39    ' mask "'" char
            picText = picText & "\\'"
          DEFAULT
            picText = picText & Chr$(buffer)
        END SELECT
      END IF
    WEND
  CLOSE hFile

  query = "insert into table (picci) values ('" & picText & "')"
  ....
END

Hope that helps
Fine regards
Rolf

Attachment: signature.asc
Description: This is a digitally signed message part.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to