How can Webspeed force a file download? - Forum - Community Groups - Progress Community

How can Webspeed force a file download?

 Forum

How can Webspeed force a file download?

This question has suggested answer(s)

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
  • 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.

  • 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.

  • 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