How can Webspeed force a file download?

Posted by dpackerSIG on 17-May-2019 16:47

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?

<SCRIPT LANGUAGE="SpeedScript">

DEFINE VARIABLE rwFileLine AS RAW        NO-UNDO.

DEFINE STREAM infile.

DEFINE VARIABLE cFileOut AS CHARACTER INITIAL "Invoice00004.pdf".
DEFINE VARIABLE cFilePDF AS CHARACTER INITIAL "/tmp/Invoice00004.pdf".

output-http-header ("Content-disposition","Attachment~;filename=" + cFileOut).
output-content-type('application/pdf').


INPUT STREAM infile FROM VALUE(cFilePDF) BINARY NO-ECHO NO-MAP NO-CONVERT.

REPEAT:
    LENGTH(rwFileLine) = 1024.
    IMPORT STREAM infile UNFORMATTED rwFileLine.
    PUT {&WEBSTREAM} CONTROL rwFileLine.
END.

LENGTH(rwFileLine) = 0.
INPUT STREAM infile CLOSE.

</SCRIPT>

Any ideas, suggestions, or assistance would be greatly appreciated!

-Dan

All Replies

Posted by goo on 17-May-2019 18:58

First why not call the appserver and get it by a temp-table record? Then you don’t have to use a file... 

Sendt fra min iPad

17. mai 2019 kl. 18:49 skrev dpackerSIG <bounce-dpackerSIG@community.progress.com>:

Update from Progress Community
dpackerSIG

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?

<SCRIPT LANGUAGE="SpeedScript">

DEFINE VARIABLE rwFileLine AS RAW        NO-UNDO.

DEFINE STREAM infile.

DEFINE VARIABLE cFileOut AS CHARACTER INITIAL "Invoice00004.pdf".
DEFINE VARIABLE cFilePDF AS CHARACTER INITIAL "/tmp/Invoice00004.pdf".

output-http-header ("Content-disposition","Attachment~;filename=" + cFileOut).
output-content-type('application/pdf').


INPUT STREAM infile FROM VALUE(cFilePDF) BINARY NO-ECHO NO-MAP NO-CONVERT.

REPEAT:
    LENGTH(rwFileLine) = 1024.
    IMPORT STREAM infile UNFORMATTED rwFileLine.
    PUT {&WEBSTREAM} CONTROL rwFileLine.
END.

LENGTH(rwFileLine) = 0.
INPUT STREAM infile CLOSE.

</SCRIPT>

Any ideas, suggestions, or assistance would be greatly appreciated!

-Dan

View online

 

You received this notification because you subscribed to the forum.  To stop receiving updates from only this thread, go here.

Flag this post as spam/abuse.

Posted by David Abdala on 20-May-2019 10:14

I'm not sure what the problem is, but from your description, you are missing the retrieval of the file from the AppServer.

You can just transfer the file to a local file, before this code you showed, or never go through a local file.

If this code is working for you downloading a WebServer local file, then it will still work by previously transfering the file from the AppServer.

Posted by egolf on 20-May-2019 12:50

Try this:

DEFINE VARIABLE mObject  AS MEMPTR     NO-UNDO.
DEFINE VARIABLE cFileOut AS CHARACTER INITIAL "Invoice00004.pdf".
DEFINE VARIABLE cFilePDF AS CHARACTER INITIAL "/tmp/Invoice00004.pdf".
    
SET-SIZE(mObject) = 0 .

output-http-header ("Content-disposition","Attachment~;filename=" + cFileOut).
output-content-type('application/x-download').

FILE-INFO:FILE-NAME = cFilePDF.

SET-SIZE(mObject) = FILE-INFO:FILE-SIZE.
COPY-LOB FROM FILE cFilePDF TO OBJECT mObject .

{&OUT-LONG} mObject .
SET-SIZE(mObject) = 0 .

Egolf Sátiro



This thread is closed