1 Reply Latest reply on Aug 22, 2006 9:25 AM by julien1

    file download

      is it possible to realize a file download via a portlet?
      via servlet the code would look something like this:
      response.setContentType ("text/plain");
      response.setHeader ("Content-Disposition", "attachment; filename=\"testfile.txt\"");
      ServletOutputStream op = response.getOutputStream ();
      InputStream in = new FileInputStream(p_dir+request.getParameter("p_file"));
      byte[] b = new byte[4 * 1024];
      int len = 0;
      while ((len = in.read(b)) != -1) {
      op.write(b, 0, len);
      }
      in.close();
      op.flush();
      op.close();

        • 1. Re: file download

          no, portlets always returned markup in an aggregated page. as you said you have to use a servlet and leverage PortletRequest.getContextPath() to provide an URI that targets the servlet that will provide the file download.