NetTalk Central

Author Topic: Serving an alternate requested file  (Read 3748 times)

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Serving an alternate requested file
« on: May 30, 2016, 04:59:25 AM »
I have this code in my WebHandler _SendFile Procedure before the Parent Call
IF  p_web.GetValue('myuniqueparameter') = 1
    SaveFileName = st.FileNameOnly(p_FileName)
    p_web.HeaderDetails.ContentDisposition = 'attachment; filename= '  & SaveFileName
END
It works perfectly giving the user the choice of opening using the default view type or saving the file with the name stored in SaveFileName.
I use tif images to store the files because it is easy to attach pages to an existing document.
I now want to serve a pdf version of the file to the user when he requests a document.
I already have a source procedure which I have created which uses PDFTools to create a PDF image from a tif.
p_FileName contains the absolute location of the tif image
My proposed solution is to create the pdf using p_FileName as the source and the created pdf image in the web folder.
Then set p_FileName to the location of the created PDF image

Like this:
IF  p_web.GetValue('myuniqueparameter') = 1
    loc:PDFName = 'web\POD368.pdf'                                   !allocate pdf name                      
    TifToPDF(CLIP(p_FileName,CLIP(loc:PDFName)               !create a pdf copy of the tif image in web folder
    p_FileName = CLIP(loc:PDFFileName)   
    SaveFileName = st.FileNameOnly(p_FileName)
    p_web.HeaderDetails.ContentDisposition = 'attachment; filename= '  & SaveFileName
END

Does this make sense? Is there a better way?
UPDATE
Doing it this way results in the attached image
IF I save the document it is correct i.e. it is the PDF file and can be opened with a PDF viewer. However the viewer still thinks it is a tif image (see attached image) and uses the default tif viewer to open the file.
How would I convince the browser that the substituted image is now pdf if I want to open it?
« Last Edit: May 30, 2016, 05:23:16 AM by terryd »
Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Serving an alternate requested file
« Reply #1 on: May 30, 2016, 04:40:47 PM »
HI Terry,

you may need to specify the content type as well.

p_web.ReplyContentType = 'application/pdf'

terryd

  • Hero Member
  • *****
  • Posts: 759
    • View Profile
    • Davcomm
    • Email
Re: Serving an alternate requested file
« Reply #2 on: May 30, 2016, 10:23:45 PM »
Hi Kevin. Thanks, that worked.
My last issue.
Using the above results in a pdf file being created in the web folder (in fact web\PDF) every time an image is viewed. I need a procedure to clear out created images since they will obviously keep on multiplying.
The procedure should remove all pdfs in the web\PDF folder older than (say) one hour
The procedure is easy enough but suggestions as to where it should be placed would be welcomed.
e.g.
Every time a user logs in
Every time a user accesses the browse
Just before, or  after new documents are added to the system
When a session is closed



Terry Davidson
Windows 10 64 bit/Windows7 64bit
Clarion 9.1.11529/Clarion10 12567
Nettalk 913
Nettalk 1015
StringTheory267/Winevent515/XFiles298/MessageBox239/Cryptonite186