Download FIle in Fatwire

270 Views Asked by At

I want to allow end-users of my site to download files from the server, I tried to use the classic method using 2 jsp files :

index.jsp :

<a href="download.jsp">download the file</a>

download.jsp :

<%    
  String filename = "file.xls";   
  String filepath = "C:\\Files\\";   
  response.setContentType("APPLICATION/OCTET-STREAM");   
  response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\"");   

  java.io.FileInputStream fileInputStream=new java.io.FileInputStream(filepath + filename);  

  int i;   
  while ((i=fileInputStream.read()) != -1) {  
    out.write(i);   
  }   
  fileInputStream.close();   
%>

But, it's not working with 2 Page Template in Fatwire 7.6.2, Is that because I am not allowed to use reponse object in Fatwire ?

1

There are 1 best solutions below

0
On

Using response object within a Sites (aka "fatwire") jsp is indeed discouraged. The typical way to make files available for download in Sites is to model the data in an asset, then use blobserver tags to render a url. See http://docs.oracle.com/cd/E29542_01/apirefs.1111/e39371/JSP/render-getbloburl.html for examples and other similar tags.

If you don't want to put these files into assets, then you may be better off not using blobserver tags and simply making them available directly through the webserver.

Phil