You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by fred-fri <fr...@dsv.su.se> on 2014/12/03 04:10:04 UTC

Serve file without download links etc

I need to implement public URLs that lead directly to files. I'm
thinking I could create a page that takes a unique file identifier as
parameter, uses that to look up the file, and serve the file. But how
can I serve the file immediately without using download links etc?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Serve file without download links etc

Posted by fred-fri <fr...@dsv.su.se>.
Ended up doing something like this:

//in Application init

mountResource("file", new ResourceReference() {
    @Override
    public IResource getResource() {
        return new AbstractResource() {
            @Override
            protected ResourceResponse newResourceResponse(Attributes
attributes) {
                final FileDescription fileDescription =

fileDescriptionService.findOne(attributes.getParameters().get("file").toLong());
                final AbstractResource.ResourceResponse resourceResponse
= new AbstractResource.ResourceResponse();

resourceResponse.setContentType(fileDescription.getMimeType());

resourceResponse.setContentLength(fileDescription.getSize());
                resourceResponse.setFileName(fileDescription.getName());
                if (resourceResponse.dataNeedsToBeWritten(attributes)) {
                    resourceResponse.setWriteCallback(new
AbstractResource.WriteCallback() {
                        @Override
                        public void writeData(Attributes attributes)
throws IOException {
                            try (InputStream data =
fileDescription.getData()) {
                                IOUtils.copy(data,
attributes.getResponse().getOutputStream());
                            }
                        }
                    });
                }
                return resourceResponse;
            }
        };
    }
});


On 2014年12月03日 12:10, fred-fri wrote:
> I need to implement public URLs that lead directly to files. I'm
> thinking I could create a page that takes a unique file identifier as
> parameter, uses that to look up the file, and serve the file. But how
> can I serve the file immediately without using download links etc?
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Serve file without download links etc

Posted by Ernesto Reinaldo Barreiro <re...@gmail.com>.
Mount a recourse?

http://wicketinaction.com/2011/07/wicket-1-5-mounting-resources/

You will need to trigger some kind of request to the server in order to be
able to download a file. See

https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow

for an alternative to download link.


On Wed, Dec 3, 2014 at 3:10 AM, fred-fri <fr...@dsv.su.se> wrote:

> I need to implement public URLs that lead directly to files. I'm
> thinking I could create a page that takes a unique file identifier as
> parameter, uses that to look up the file, and serve the file. But how
> can I serve the file immediately without using download links etc?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Regards - Ernesto Reinaldo Barreiro