Posted: 6 Oct 2016 2:16 EDT Last activity: 13 Dec 2016 19:54 EST
How to download file from server using anchor links?
We are using pega 6.1 SP2. We have a requirement to show the list of files in the server location as links to download but server location is a folder parallel to PegaTempDir folder but not within the pegaTempDir. How to access the path?
Within that Stream Rule; you can search for the text that is displayed in the Export Process:
"Zip file created. Click here to save"
// Provide a download link to save the file locally.
var strFilePath = '<pega:reference name="pxThread.pxReqExportURI" mode="normal" />' +
'<%= PRFile.separator %>' + strFileName;
lblMessage.innerHTML = "<html><a class=ProgLabel href=\"" + strFilePath + "\">" +
"<U><B>Zip file created. Click here to save " + strFileName +
" file locally</B></U></a></html>";
So I took this and created a test Activity of my own which does this:
oops: I just noticed you needed to load a file from outside 'PegaTemp' (which includes 'StaticContent').
You probably want to use 'PRFile' and/or standard Java 'File' methods to move that file into the 'StaticContent' directory - not great security to have your App referencing arbitary directories with a URL pointing at them though.....
So - does PRPC even need to see these files (are you just providing a mechanism to download files from a web server?) You could build your own Servlet that does this and include a reference to this custom Servlet from your PRPC's 'web.xml'.
In the case above: this really has nothing to do with PRPC: you would just be using the App Server that PRPC is deployed to provide a 'static' web site really ?
Alternatively: to avoid having to customize PRPC's 'web.xml' (which probably isn't a good idea unless you really have to); you could deploy a complete separate Web App ; which you can link to from PRPC (no problem: links are followed by the Browser; not the Server); if you are using Tomcat; there is a built-in Servlet to allow this sort of thing ("Default Servlet") : see https://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html for instance.
One thing about using a separate Web App: this will not be authenticated by the Logged-in PRPC Operator - you may need to take that into account also.
Or else: consider using a File Listener to process the files and store them within PRPC; then use standard mechanism (JSP 'pega tags' etc) to allow the downloading/streaming of the copies of the files.
Or (if your PRPC system is hosted on Linux or Unix) : consider using 'Symbolic Links' to make the files available within the standard 'ServiceExport' directory ? (Note: I haven't tried this, so it may be the Web Server/Servlet won't follow Symbolic Links, but it's worth a shot).