NetTalk Central

Author Topic: How to refer to web folder, upload folder, etc  (Read 3068 times)

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
How to refer to web folder, upload folder, etc
« on: October 11, 2014, 10:37:51 AM »
I'm trying to do some post processing on files sent to the upload folder.  I can't figure out how to refer to them.  Here is a sample of my code in the Post Insert embed:

st2.LoadFile(p_web.site.WebFolderPath&'\ExpirationJS.txt')
Message(st2.getvalue())

L# = QuickPDF.LoadFromFile('\web\Uploads\'&Clip(Con:Consent_Name), '')
Message(L#, 'Load File')

E# = QuickPDF.LastErrorCode()
Message(E#, 'Error')

O# = QuickPDF.PageJavaScriptAction('O', st2.GetValue())
Message(O#, 'Insert Script')

QuickPDF.SaveToFile('\web\Uploads\'&Clip(Con:Consent_Name))
st3.LoadFile('\web\Uploads\'&Clip(Con:Consent_Name))
st3.ToBlob(Con:Consent_File)

This has not worked for me.  Where have I gone wrong?

Thanks

MyBrainIsFull

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: How to refer to web folder, upload folder, etc
« Reply #1 on: October 11, 2014, 06:20:20 PM »
Hi, I think you are saying here your process is not working because you cant identify the uploaded file.

In the WebHandler you have a Proc called "P_Web.SaveFile"
This is the handler saving the file to disk, it has a name of p_filename

In my example I wanted to change the path of the incoming file depending on the user working with a lesson or a assessment,   Here is my code in the handler, you should see how I am using the filename

Note, the Case statement is me trapping which form sent this in.

If you want an app that does this, let me know

K



p_web.SaveFile PROCEDURE(STRING p_name,<STRING p_filename>)

ReturnValue          ANY

! Start of "NetTalk Method Data Section"
! [Priority 5000]

! End of "NetTalk Method Data Section"

  CODE
  ! Start of "NetTalk Method Executable Code Section"
  ! [Priority 2500]
   Case self.GetSessionValue('updateFile')
     of 'LessonLine'             ! this is a D&D in redactor
        if p_filename > ''       ! D:\appname\web\uploads\cat.jpg
          if p_name = 'file'     ! changed to LL:LessonId
            CreateDirectory( 'Web\Lesson\'  & self.gsv('LL:LessonId') )
                        
            s200 =  p_filename  
            s200 = strTh.FileNameOnly( s200 )
            self.ssv('_KHdr FNameOnly=', clip(s200) )
            
            s200 = 'Lesson\'  & self.gsv('LL:LessonId') &'\'& s200        ! Web relative                  
            p_filename = clip(p_web.site.WebFolderPath) &'\'& s200
            self.ssv('_KHdr FName=', p_filename )
  
        ;.;.
        
     of 'LessonResource'  
        if self.gsv('lres:filename') > ''    
           s200 = strTh.FileNameOnly( self.GetSessionValue('lres:filename') )
    
           CreateDirectory( 'Web\Lesson\'  & self.gsv('les:id') )
           s200 = 'Lesson\'  & self.gsv('les:id') & '\' & s200              
           self.SSV('lres:filename', s200)
           p_filename = clip(p_web.site.WebFolderPath) &'\'& s200
         self.ssv('_KHdr FName=', p_filename )
        end
        
     of 'AssesmentMasterQuestion'
        !- then we are saving an asssessment - change uploads  to Assessment\id
        if self.GetSessionValue('amq:mcimage') >''
           s200 = strTh.FileNameOnly(self.GetSessionValue('amq:mcimage') )
    
           CreateDirectory( 'Web\Assessment\'  & self.gsv('amq:id') )
           s200 = 'Assessment\'  & self.gsv('amq:id') & '\' & s200              
           self.ssv('amq:mcimage', s200)
           p_filename = clip(p_web.site.WebFolderPath) &'\'& s200
         self.ssv('_KHdr FName=', p_filename )
        end      
   end  
  
« Last Edit: October 11, 2014, 06:22:35 PM by MyBrainIsFull »

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: How to refer to web folder, upload folder, etc
« Reply #2 on: October 11, 2014, 07:56:15 PM »
Thanks for the response.  I have been working all day and made some progress. 

Here is a bit of background.  I'm uploading PDF files and adding a small JavaScript to each with an expiration date.  I have the Upload field set to send the PDF's to a BLOB and to the Uploads folder.  This works fine.  Right after the upload, I want to process the PDF with the QuickPDF library that I have installed.  I have this working pretty well, except for updating the BLOB with the revised PDF.  Here is the code so far, from the SaveFile Routine, End embed:

st2.LoadFile('.\ExpirationJS.txt')
Message(st2.getvalue(), 'Load Script')

L# = QuickPDF.LoadFromFile(p_web.GetValue('Con:Consent_Name'), '')
Message(L#, 'Load File/String')

E# = QuickPDF.LastErrorCode()
Message(E#, 'Error')

O# = QuickPDF.PageJavaScriptAction('O', st2.GetValue())
Message(O#, 'Insert Script')

S# = QuickPDF.SaveToFile('XXXMyTest.pdf')
st3.LoadFile('XXXMyTest.pdf')
st3.ToBLOB(Con:Consent_File)

As you can see I'm using StringTheory to handle the data.  I'm able to get a final revised PDF that contains the added JavaScript as seen near the end of the code where I create XXXMyTest.pdf.  This is currently created in the app folder but ideally I want to update the BLOB (Con:Consent_File) with this new PDF.  StringTheory ToBlob and FromBlob have not worked for me during all this.

So now I'm looking for a solution to get my Blob updated.  Any thoughts?

Thanks,

Jeff

JohanR

  • Sr. Member
  • ****
  • Posts: 341
    • View Profile
    • Email
Re: How to refer to web folder, upload folder, etc
« Reply #3 on: October 12, 2014, 12:34:19 AM »
Hi Jeff


Have you checked if any errors occur with stringtheory,
there should be an errortrap embed

Check your filenames to make sure files are there.


Johan


kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: How to refer to web folder, upload folder, etc
« Reply #4 on: October 12, 2014, 03:40:27 PM »
Johan,

Yup...no errors.  Get a return of 1 from the LoadFile method:

S# = QuickPDF.SaveToFile('XXXMyTest.pdf')
LF# = st3.LoadFile('XXXMyTest.pdf')
Message(LF#, 'Load File')                             !Get a 1 which indicates success loading the file
B# = st3.ToBLOB(Con:Consent_File)           !Get a 1 which indicates success storing to the BLOB

Still, when I retrieve the blob contents it is the original file uploaded, ie not updated with the revised contents.

Thanks,

Jeff

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: How to refer to web folder, upload folder, etc
« Reply #5 on: October 12, 2014, 10:53:02 PM »
Have you checked if the revised file is being appended to the end of the blob?

kingja

  • Sr. Member
  • ****
  • Posts: 261
    • View Profile
    • Email
Re: How to refer to web folder, upload folder, etc
« Reply #6 on: October 13, 2014, 07:24:36 AM »
Kevin,

Interesting idea.  I'll look into it.  However, I may have a solution.  The last three lines of my code in the SaveFile Routine embed, are the ones that do the BLOB update.  I moved these three lines to the Validate Insert embed and it works as expected, now updating the BLOB.  Perhaps a "timing" issue?  I'm still experimenting.

Thanks,

Jeff