[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on how to get a pdf in a db blob field using Gambas
[Thread Prev] | [Thread Next]
- Subject: Re: Question on how to get a pdf in a db blob field using Gambas
- From: Tim Dickson <dickson.tim@xxxxxxxxxxxxxx>
- Date: Thu, 18 Apr 2024 16:21:37 +0100
- To: user@xxxxxxxxxxxxxxxxxxxxxx
i wouldcheck the size of $sPdfRapport before trying to write it to the database, just in case your SaveRecord function is getting called not when you expect it, and $sPdfRapport is a blank string.
regards, Tim On 18/04/2024 15:23, gbWilly wrote:
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) EndThis 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 EndTo load the image from blobfield you recreate the .jpg file from the longblob and next load it into your pictureboxIt 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) ThenpbxOK.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.
Question on how to get a pdf in a db blob field using Gambas | gbWilly <gbWilly@xxxxxxxxxxxxxx> |