Force a pdf download in Webspeed

I'm trying to download a pdf document via Webspeed. The document is available on the application server, but not on the web server, so I can't just link to it.

The code below (along with all other examples I can find on the web) just returns a web page with the headers, followed by the PDF code embedded in the browser. Does anyone have an idea as to what I'm missing?

Code:
<SCRIPT LANGUAGE="SpeedScript">

 
{src/web/method/wrap-cgi.i}
 
DEFINE STREAM infile.
DEFINE VARIABLE vdata AS RAW NO-UNDO.
/*
  I've tried different variations on http-headers and content types, nothing seems to work :(
*/

output-http-header("Content-Description":U, "File Transfer":U). 


output-http-header("Content-Type":U, "application/pdf":U). 

output-http-header("Content-Transfer-Encoding":U, "binary":U).
output-http-header("Content-Disposition":U, SUBSTITUTE('attachment~;filename="&1"':U,
                                                       "Invoice0004.pdf")
                                                       ).
OUTPUT-CONTENT-TYPE("application/pdf").                                                                       
INPUT STREAM infile FROM /tmp/Invoice00004.pdf BINARY NO-ECHO NO-CONVERT NO-MAP.
LENGTH(vdata) = 338966.
REPEAT:
    IMPORT STREAM infile UNFORMATTED vdata.
    PUT {&WEBSTREAM} CONTROL vdata.
END.
LENGTH(vdata) = 0.
INPUT STREAM infile CLOSE.

 
</SCRIPT>

Thanks for any help or advice you can provide!

-Dan
 

Cecil

19+ years progress programming and still learning.
Try this. I've incaptulated the in procedure "outputeader".

REF:

Code:
<SCRIPT LANGUAGE="SpeedScript">
{src/web/method/wrap-cgi.i}

DEFINE STREAM infile.
DEFINE VARIABLE vdata AS RAW NO-UNDO.
/*
 Encapsulated into a Procedure Header.
*/
PROCEDURE outputHeader:
output-http-header("Content-Description":U, "File Transfer":U).


output-http-header("Content-Type":U, "application/pdf":U).

output-http-header("Content-Transfer-Encoding":U, "binary":U).
output-http-header("Content-Disposition":U, SUBSTITUTE('attachment~;filename="&1"':U,
                                                       "Invoice0004.pdf")
                                                       ).
OUTPUT-CONTENT-TYPE("application/pdf").

END PROCEDURE.

INPUT STREAM infile FROM /tmp/Invoice00004.pdf BINARY NO-ECHO NO-CONVERT NO-MAP.
LENGTH(vdata) = 338966.
REPEAT:
    IMPORT STREAM infile UNFORMATTED vdata.
    PUT {&WEBSTREAM} CONTROL vdata.
END.
LENGTH(vdata) = 0.
INPUT STREAM infile CLOSE.


</SCRIPT>
 
Last edited:

Cecil

19+ years progress programming and still learning.
Use the copy-lob statement to read the file and write to memptr. THen use the memprt to write to the webstream.

Code:
set-size(memptrPDF) = 0.

COPY-LOB FROM FILE infile TO object memptrPDF.

{&OUT-LONG} memptrPDF.

set-size(memptrPDF) = 0.
 
Top