Hi,

thanks for links with ideas. I am new in Tapestry I use Example
App<http://jumpstart.doublenegative.com.au/jumpstart/theapp/login>
from
Jumpstart tutorial . I added File
Upload<http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/fileupload>
to
Example App and HSQL table for uploaded file names. In Example App is
used Protecting
Pages<http://jumpstart.doublenegative.com.au/jumpstart/examples/infrastructure/protectingpages>
and
I can not download uploaded file by simple href even if I am logged in as a
admin user.

How to allow to download file from upload-path?

I use simple link in  tml file

<a t:type="eventlink" t:event="returnstreamresponse" href="#">download</a>

and I also added  onReturnStreamResponse into java file from jumpstart
tutorial from this link.

StreamResponse onReturnStreamResponse() {
        return new StreamResponse() {
            InputStream inputStream;

            @Override
            public void prepareResponse(Response response) {
                ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
                inputStream =
classLoader.getResourceAsStream("regoznapp/enterprise/src/main/resources/return.txt");

                // Set content length to prevent chunking - see
                //
http://tapestry-users.832.n2.nabble.com/Disable-Transfer-Encoding-chunked-from-StreamResponse-td5269662.html#a5269662

                try {
                    response.setHeader("Content-Length", "" +
inputStream.available());
                }
                catch (IOException e) {
                    // Ignore the exception in this simple example.
                }
            }

            @Override
            public String getContentType() {
                return "text/plain";
            }

            @Override
            public InputStream getStream() throws IOException {
                return inputStream;
            }
        };
}

Petr

Reply via email to