[Seaside] Serving files from within Seaside

Boris Popov, DeepCove Labs boris at deepcovelabs.com
Tue Dec 18 18:19:21 UTC 2012

We added the below to our components,

(html anchor)
callback: [self savePDF];
with: 'Save PDF'

                                downloadBytes: (<pdf generation>)
                                mime: 'application/pdf'
                                filename: ('Report Title <1s>.pdf' expandMacrosWith: (Date today printUsing: 'yyyy-mm-dd')).

downloadBytes: bytes mime: mime filename: filename

                self requestContext respond:
                                                [:response |
                                                response document: ((bytes seasideMimeDocument)
                                                                                                mimeType: mime;
                                                                                                fileName: filename;

From: seaside-bounces at lists.squeakfoundation.org [mailto:seaside-bounces at lists.squeakfoundation.org] On Behalf Of Jon Paynter
Sent: Tuesday, December 18, 2012 1:10 PM
To: Seaside - general discussion
Subject: Re: [Seaside] Serving files from within Seaside

> Hi there,
> I know people consider serving files a job that should be handled by a
> "real" http server rather than Seaside. In most cases, esp. for static
> resources that can be accessed by the public, that is absolutely the case.
> But I need to serve files in a callback. The files are being partly
> calculated and read from a DB and should be available for download by
> clicking on a link.
> I've been looking into WAFileLibrary and WAFileHandler, but am not sure
> where to start.
> What I want to do is something like:
> html anchor
>  callback: [self calculateChartAndServeIt]
>  with: 'Download full chart'.
> I know I will have to respond:, but can I do that in a callback?
> Joachim

I do a very similar thing in my application.  Generate a file and serve it up to the user.  So far this has worked well:
downloadtext: contents named: aFilename
    "trigger a file download operation for aFilename with the contents in contents"

    self requestContext respond: [ : response |
        response contentType: 'text/plain';
        attachmentWithFileName: aFilename;
        nextPutAll: contents.

where "contents" is a string containing the text of the file to download

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20121218/0bb69948/attachment.htm

More information about the seaside mailing list