NetTalk Central

Author Topic: Save a photo to a blob field  (Read 168 times)

Alberto

  • Hero Member
  • *****
  • Posts: 1774
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Save a photo to a blob field
« on: June 01, 2022, 07:59:04 AM »
Hi Bruce,

Im taking photos and I need to save it to a blob.

In the SaveFile routine Ive added a few lines that seams to be OK but the blob is not saved

SaveFile::pim:Link  Routine
  data
loc:filename  string(255)   ! full server-side pathname to file on the server disk.
str           StringTheory
  code
  loc:filename = pim:Link
  str.SetValue(str.Random(8,st:Lower) & '.png')
  loc:filename = p_web.RenameFile('Link',str.GetValue())
  p_web.SaveImage('pim:Link',loc:filename,p_web.GetValue('_image_'))
  pim:Link = p_web.MakeWebRelative(loc:filename)
  p_web.SetSessionValue('pim:Link',pim:Link)

        p_web.AddLog('gen blob from '&loc:filename)
    str.LoadFile(loc:filename)                                      !the file exists
        p_web.AddLog('len: '&str.len())                            !str has a good len
    str.ToBlob(pim:blobimagen)                               
    p_web.SetSessionValue('pim:blobimagen',pim:blobimagen)

But the blob is not saved... Any idea?

BTW, I dont found any "save as blob" option in the template in NT11 nro in NT12.

Thanks!

Alberto Michelis


-----------
Regards
Alberto

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10733
    • View Profile
Re: Save a photo to a blob field
« Reply #1 on: June 01, 2022, 10:28:10 PM »
I'll see about adding the template option for build 12.42

Alberto

  • Hero Member
  • *****
  • Posts: 1774
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Save a photo to a blob field
« Reply #2 on: June 02, 2022, 02:49:12 AM »
Ok, thank you very much, but what about NT11, my app is still in NT11.
I dont pretend you adding the same feature to nt11 but please tell me how to do it by code.
I certainly dont understand why my code does not work.
Thanks again.
Regards

PD:I tried this too and the blob is not saved, see pic
« Last Edit: June 02, 2022, 07:27:19 AM by Alberto »
-----------
Regards
Alberto

osquiabro

  • Hero Member
  • *****
  • Posts: 557
    • View Profile
    • Email
Re: Save a photo to a blob field
« Reply #3 on: June 02, 2022, 09:33:07 AM »
my code for blobs is in ValidateInsert  Routine and work in nt 11

ValidateInsert  Routine
  ! Start of "On Insert : Form ends : before disk write (start)"
  ! [Priority 5000]
  Bildo:DocumentExtension =  upper(st.ExtensionOnly(p_web.GSV('Loc:Path')))
  IF NOT INLIST(Bildo:DocumentExtension,'XLS','PDF','JPG','GIF','TIFF','PNG')     
      loc:Alert = 'INVALID DOCUMENT TYPE'
      loc:invalid = 'Loc:Path'
      p_web.Script('ntAlert("Invalid Document Type.","ALERT");')
      p_web.SSV(Loc:Path,'')
      CLEAR(Loc:Path)
      CLEAR(Bildo:DocumentExtension)
      EXIT
  ELSE             
      IF FileToBLOB(p_web.GSV('Loc:Path'),Bildo:Documents)
          loc:Invalid = 'Loc:Path'
          if not loc:alert then
              loc:Alert = ' Error al tratar de Grabar el Archivo ' & clip(Bildo:Description)
          end
      END     
  END

Alberto

  • Hero Member
  • *****
  • Posts: 1774
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Save a photo to a blob field
« Reply #4 on: June 02, 2022, 10:20:48 AM »
Ive tried using:

if pim:Link
    p_web.AddLog(longpath()&'\web'&pim:link)
    if  FileToBLOB(longpath()&'\web'&pim:link,pim:blobimagen)
        p_web.AddLog( 'Was not copied -  ERRORCODE: ' & ERRORCODE())
    end
    p_web.AddLog('size: '&pim:blobimagen{PROP:Size})
END           

In Validate, FileToBlob is ok
Size is Ok
But the blob field is not saved
:-(

Its a MsSql backend and what arrives to the server for an update is
UPDATE p_Imagenes SET LINK = @P1 WHERE ID = @P2 ','\uploads\zxsrdajb.png',2
+
only the link is updated but not the blob

and for an insert
INSERT INTO p_Imagenes (ID,IDENVIO,LINK,FECHA,TIPO,HORA,BLOBIMAGEN) VALUES (@P1,@P2,@P3,@P4,@P5,@P6,@P7)',4,61,'\uploads\cpfliibu.png','2022-06-02',0,'15:36',NULL

saving NULL to the blob



« Last Edit: June 02, 2022, 10:38:29 AM by Alberto »
-----------
Regards
Alberto

osquiabro

  • Hero Member
  • *****
  • Posts: 557
    • View Profile
    • Email
Re: Save a photo to a blob field
« Reply #5 on: June 03, 2022, 04:01:28 AM »
como tienes definido el campo blob en el SQL? y le tienes marcado el Binary en el DCT? otro detalle estas usando odbc o driver nativo? si es nativo usa el SQLClient 11 de lo contrario usara el 2005 por defecto y con ese client hay un bug con los campos blob, llevo a?os trabajando con MSSQL y no tenido problemas con los blob, ya tendo una base de datos de 500gb de imagenes

How do you have the blob field defined in the SQL? and do you have the Binary marked in the DCT? another detail are you using odbc or native driver? If it is native, use SQLClient 11, otherwise it will use 2005 by default and with that client there is a bug with blob fields, I have been working with MSSQL for years and have had no problems with blobs, I already have a 500GB image database

Alberto

  • Hero Member
  • *****
  • Posts: 1774
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Save a photo to a blob field
« Reply #6 on: June 03, 2022, 07:43:42 AM »
This is not the problem, Im saving blobs from my desktop app without problem.
-----------
Regards
Alberto

osquiabro

  • Hero Member
  • *****
  • Posts: 557
    • View Profile
    • Email
Re: Save a photo to a blob field
« Reply #7 on: June 03, 2022, 08:09:11 AM »
I'm saving  blobs in mssql from NT 8 above with no problem.

as bruce says create a small example

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 10733
    • View Profile
Re: Save a photo to a blob field
« Reply #8 on: June 05, 2022, 10:53:31 PM »
Hi Alberto,
from my look at your code you are writing the photo to a session value.
At some point you'll need to move that session value into the blob field, before it is saved.

I've added the feature to NetTalk 12, but there were a couple moving parts to get into sync before it worked right.
So just debug your code, and follow it through, and you should be ok.

Cheers
Bruce

Alberto

  • Hero Member
  • *****
  • Posts: 1774
    • MSN Messenger - alberto-michelis@hotmail.com
    • View Profile
    • ARMi software solutions
    • Email
Re: Save a photo to a blob field
« Reply #9 on: Today at 09:00:05 AM »
Ok, I think I discover whats happening.
Im saving the blob in a popup form
If I try to save the blob in an insert, it does not work, I think may be the file is not completly saved when doing the filetoblob.
Opening again the form and saving, the blob is saved ok.
Where in the form code must I add the filetoblob code for it to be saved in an insert?
Ive tried many embeds and nothing work.
ValidateInsert, PostInsert, SaveFile, etc.
Thanks
-----------
Regards
Alberto