NetTalk Central

Author Topic: Store PDF documents in BLOB, Part 1  (Read 6498 times)

jking

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Email
Store PDF documents in BLOB, Part 1
« on: April 26, 2012, 04:59:09 PM »
Bruce,

     I have a NT 6.27 app containing two files, XLog and XCRF.  XCRF is related to XLog via a sys_id field.  I display a browse of the XCRF file on a tab.  Here I want to simply insert a record that stores a chosen PDF in a blob field. 
     XCRF contains sys_id, date, file_description and file_contents (blob) fields.  Upon insert I choose the file upload button and navigate out to my local drive for a PDF document.  Upon returning I want the file_description field to fill with the name of the file.  Upon saving, the pdf file should be saved to the blob.  I have this working by placing the following code in the validate embed of the file upload field:

     If glo:CRF_Filename <> ''
         XCRF:CRF_FileName = Clip(glo:CRF_Filename)                       !!CRF_Filename is the description
         ImageEx:FileToBLOB(Clip(glo:CRF_Filename), CRF:CRF_File)  !!CRF:CRF_File is the blob in XCRF
     End

glo:CRF_Filename is set to Clip(self.site.WebFolderPath)&'\'&ReturnValue in the HandleFile embed of the WebHandler procedure.

     This seems to work well with Inserts.  For example, I insert abc.pdf and xyz.pdf and both appear in the browse and the pdf contents are in the blob.  However, when I click change to view an entry, the description field (CRF_Filename) always fills with the description of the last record added, in this case xyz.pdf.  Is there a better way to accomplish this?  That is a better embed I should use?  I have tried many others such as Validate All, Validate Insert, Pre and Post Insert, etc.  I have also looked at examples 26 and 40, and other postings here for hints.

Thanks,

Jeff King


 

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Store PDF documents in BLOB, Part 1
« Reply #1 on: April 26, 2012, 05:27:16 PM »
Firstly I would get rid of glo:CRF_Filename and replace with a SSV. It's going to create bigger problems when multiple users log in the way you have it.

Then when the form opens reset the SSV to = '' that way it won't trigger your code.

jking

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Email
Re: Store PDF documents in BLOB, Part 1
« Reply #2 on: April 26, 2012, 06:58:44 PM »
Kevin,

     Thanks, that sounds like good advice.  So I changed the code in the HandleFile embed to:

          p_web.SSV('myCSRFileName', Clip(self.site.WebFolderPath)&'\'&ReturnValue)

     Then in the validate embed of the file upload field (loc:Upload_Filename) I use:

        1.  CRF:CRF_FileName = p_Web.GSV('myCRFFileName')
        2.  ImageEx:FileToBLOB(Clip(glo:CRF_Filename), CRF:CRF_File)

     Is this what you had in mind?  If so, I'm confused by setting the SSV to = '' when the form opens.  If I do this, will line 1. above work?  It seems it will always be blank.

Thanks,

Jeff

jking

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Email
Re: Store PDF documents in BLOB, Part 1
« Reply #3 on: April 26, 2012, 07:26:13 PM »
Kevin,

     Something else strange...If I select the first record of two, the form actually displays record two.  Please see the attached image.  In addition, if I try to delete the second record, it actually deletes the first.  I have done something wrong here.  Any thoughts?

Thanks,

Jeff

[attachment deleted by admin]

jking

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Email
Re: Store PDF documents in BLOB, Part 1
« Reply #4 on: April 26, 2012, 07:29:07 PM »
Sorry....reverse that, If I select record two, record one is displayed in the form.

Jeff

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Store PDF documents in BLOB, Part 1
« Reply #5 on: April 26, 2012, 07:51:40 PM »
It's a bit hard to comment without an example but this may work

Add step 3 below

1.  CRF:CRF_FileName = p_Web.GSV('myCRFFileName')
2.  ImageEx:FileToBLOB(Clip(glo:CRF_Filename), CRF:CRF_File)
3 p_web.SSV('myCSRFileName','')

In step 2 you still refer to the glo variable which I assume is just a typo.

As for picking up the wrong record it's probably the unique id SSV that has changed. Try to comment out any code to get that working first and then work around the problem.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11302
    • View Profile
Re: Store PDF documents in BLOB, Part 1
« Reply #6 on: April 27, 2012, 12:29:34 AM »
I think the File Upload program does everything you "want" to do - right Jeff?
apart from the Blob bit.

So I'm thinking what you haven't got it set up quite like the example. So the fastest way to a quick answer is if you post an example of what you do have, and we can go from there.

cheers
Bruce

jking

  • Sr. Member
  • ****
  • Posts: 422
    • View Profile
    • Email
Re: Store PDF documents in BLOB, Part 1
« Reply #7 on: April 27, 2012, 07:16:15 AM »
Bruce and Kevin,

     I have this sorted out now.  I neglected to create a unique autonumbered key in the child file.  Now I'm on to part two...how to add a button in the last column to call/view the PDF stored in the BLOB.  Any hints before I get started?

Thanks,

Jeff

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11302
    • View Profile
Re: Store PDF documents in BLOB, Part 1
« Reply #8 on: April 27, 2012, 08:47:15 PM »
The "FileDownload" example will be useful here. It has a button in a browse that retrieves a document. It also, I think, has some code (in webhandler) showing how to retrieve a doc from a blob, instead of from the disk.

cheers
Bruce