Page 1 of 1

Adding jpeg to a database and browsing them

Posted: Sat Sep 01, 2007 9:46 am
by Willy
Hello,

I use a MySQL engine to store data.

I want to add a collumn with a JPEG-picture. I know that MySQL can store bitmaps (in a blob I think)
But how can I store a JPG or another graphical file into the databank. How can I read it back to show it into a xBrowse

Greetings and thanks,

Willy

Posted: Sat Sep 01, 2007 3:27 pm
by reinaldocrespo
Willy;

Hi.

Set a new table with at least two fields. The first field is the key that ids the record back to the master table and the 2nd field is a BLOB field. Then using BLOBIMPORT you can store the jgp (after scanning the image) into the binary field. Using BLOBEXPORT you can recreate the jgp file and display. Works quite well.

You could also add a BLOB field to the table in question and do it directly to that field.


Reinaldo.

Posted: Sat Sep 01, 2007 3:50 pm
by yury
hi Willy,

see this sample in FiveWin.com.br


http://www.fivewin.com.br/exibedicas.asp?id=801


regards

Posted: Tue Sep 04, 2007 1:51 pm
by Willy
I have done already some tests.
I do further testing. It seems it will work but I have still some questions.

Is'nt it so that with the mentioned functions there is made a temporary file on the harddisk before paintig it in a screen.

Is'nt there a solution that paint the bitmap without writing to hardisk.

Thanks,

Greetings.

Willy.

Posted: Wed Sep 05, 2007 11:54 am
by Willy
The BlobExport() function gives an unresolved external.
Is this function added in the commercial SQL driver from xHarbour.

I also tried to download the Locadora example from the Brazilian Site. To make this test complete I need also the structure of the database.

Is'nt this only a working executable. Is'nt there also a code example.

Thanks

Willy

Posted: Wed Sep 05, 2007 3:07 pm
by dbzap
Load the image to memvar ...

Code: Select all

             cImagen := ""
             nBytes  := 0

             nHandle := FOpen( AllTrim( (PasoLink)->DocuExte ) )
             While .T.
                nBytes := FRead( nHandle, @cBuffer, nBufSize )
                If nBytes > 0
                   cImagen += SubStr( cBuffer, 1, nBytes )
                Else
                   EXIT
                EndIf
             EndDo
             FClose( nHandle )

             If !Empty( cImagen )
                cBase64 := cMimeEnc( cImagen )  // transforma en texto
                UPDATE EMAELINK SET TEXTO=cBase64
                BREAK
             EndIf
The read data

Code: Select all


   cDocuExte := AllTrim( Vcc(TMaes,"DOCUEXTE") )
   cBase64   := cMimeDec( Vcc(TMaes,"TEXTO") )  // se des-transforma desde texto !!

   If ( nPos  := RAT( "\", cDocuExte) )<>0
      cFile := StrTran( cDocuExte, SubStr( cDocuExte, 1, nPos ), "" )
   Else
      cFile := cDocuExte
   EndIf

   If "PDF" $ UPPER(cFile)
      lEsPDF := .T.
   Else
      lEsPDF := .F.
   EndIf

   cFile := DEFATMP + "\" + cFile

   nHandle := FCreate( cFile )
   FWrite( nHandle, cBase64 )
   FClose( nHandle )

   If lEsPDF  // no se por que solo se llama con 2 llamadas
      Shellexecute( oPadre:hwnd, "open", cFile )
      Shellexecute( oPadre:hwnd, "open", cFile )
   Else
      Shellexecute( oPadre:hwnd, "open", cFile )
   EndIf

-------------- SPANISH ON -------------------

Lo que hice fue, leer el archivo en forma binaria, transformarlo a Base64 ( texto ), guardarlo, y para recuperarlo lo leo de la base de datos, y lo vuelvo a su forma original, lo pongo en un archivo y lo guardo ( fwrite ), luego lo visualizo. Eso....
Saludos