[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Question on how to get a pdf in a db blob field using Gambas
[Thread Prev] | [Thread Next]
- Subject: Question on how to get a pdf in a db blob field using Gambas
- From: gbWilly <gbWilly@xxxxxxxxxxxxxx>
- Date: Thu, 18 Apr 2024 14:23:44 +0000
- To: Gambas Mailing List <user@xxxxxxxxxxxxxxxxxxxxxx>
Hi all, I've made Gambas applications where I stored images in longblob fields of a Mariadb with succes doing something like below: Private $sImage As String Public Sub btnSelectImage_Click() Dialog.Filter = ["*", "All Files"] Dialog.Title = "Selecteer de collar afbeelding" If Dialog.OpenFile() Then Return $sImage = File.Load(Dialog.Path) pbxImage.Picture = Picture.Load(Dialog.Path) End This way I can load an imagefile into a picturebox to show and at the same time apparently store the imagefile in a string variable ($sImage) To save the image into a database longblob field named "Foto" I do: Private Sub SaveRecord() Dim rResult As Result rResult = DBase.ConLive.Create("Students") DBase.ConLive.Begin rResult["Foto"] = $sImage '<-- here is where the magic happens rResult.Update DBase.ConLive.Commit Catch DBase.ConLive.Rollback Error.Clear End To load the image from blobfield you recreate the .jpg file from the longblob and next load it into your picturebox It goes something like (skipping the getting the result part here): Dim sContent As String sContent = rResult["Foto"] If Not IsNull(sContent) Then hFile = Open User.Home &/ "test.jpg" For Create Write #hFile, sContent, Len(sContent) Close #hFile pbxImage.Picture = Picture.Load(User.Home &/ "test.jpg") Endif Now I tried something likewise with pdf where I do: Private $sPdfRapport As String Public Sub btnSelectPdf_Click() Dialog.Filter = ["*", "All Files"] Dialog.Title = "Selecteer de collar afbeelding" If Dialog.OpenFile() Then Return $sPdfRapport = File.Load(Dialog.Path) Wait 0.10 If Not IsNull($sPdfRapport) Then pbxOK.Picture = Icons.Ok32 ´-> load an ok icon from my library (for visual reference) Else pbxOK.Picture = Icons.OkNo32 ´-> load an not ok icon from my library Endif End Private Sub SaveRecord() Dim rResult As Result rResult = DBase.ConLive.Create("Rapporten") DBase.ConLive.Begin rResult["Pdf"] = $sPdfRapport '<-- error -1 rResult.Update DBase.ConLive.Commit Catch DBase.ConLive.Rollback Error.Clear End Trying to get the $sPdfRapport into the longblob filed Pdf gave error -1 So apparently Mariadb did not like that. I know it is possible to get a pdf in a longblob, many php examples to be found on the web. I need this solved with gambas (not php), so any suggestions are welcome. gbWilly Sent with [Proton Mail](https://proton.me/) secure email.
Re: Question on how to get a pdf in a db blob field using Gambas | gbWilly <gbWilly@xxxxxxxxxxxxxx> |
Re: Question on how to get a pdf in a db blob field using Gambas | Tim Dickson <dickson.tim@xxxxxxxxxxxxxx> |
Re: Question on how to get a pdf in a db blob field using Gambas | Christof Thalhofer <chrisml@xxxxxxxxxxx> |