Serving files from within Seaside

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Serving files from within Seaside

jtuchel
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
Reply | Threaded
Open this post in threaded view
|

Re: Serving files from within Seaside

Karsten Kusche
Hi Joachim,
 
I know I will have to respond:, but can I do that in a callback?


yes you can. the action phase responds with a redirect to switch to the render phase but you can also just respond with a file. I think WAAnchor>>document: and its variations do what you need.

Kind Regards
Karsten


 

--
Sent from the Seaside General mailing list archive at Nabble.com.
_______________________________________________
seaside mailing list


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Serving files from within Seaside

DiegoLont
In reply to this post by jtuchel
Hi Joachim,

Looking into WAFileLibrary and WAFileHandler won't help a lot: you get easily lost. They are great for serving static files, and do some buffering and such.

In Seaside 3.x the answer is more simple. Your code looks fine, the method you want to make looks something like:

calculateChartAndServeIt
        self requestContext respond: [ :response |
                response
                        doNotCache;
                        document: self calculateChart ]

Diego

On Dec 18, 2012, at 8:53 AM, jtuchel wrote:

> 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
>
>
>
>
> --
> View this message in context: http://forum.world.st/Serving-files-from-within-Seaside-tp4659745.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Serving files from within Seaside

DiegoLont
In reply to this post by jtuchel
And looking at my own code, you probably want this hint too:

the document you pass to the response should be a WAMimeDocument, best created with:
        on: <documentdata>
        mimeType: WAMimeType main: <…> sub: <…>
        fileName: <the default name the client can save this>

On Dec 18, 2012, at 8:53 AM, jtuchel wrote:

> 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
>
>
>
>
> --
> View this message in context: http://forum.world.st/Serving-files-from-within-Seaside-tp4659745.html
> Sent from the Seaside General mailing list archive at Nabble.com.
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Serving files from within Seaside

Jon Paynter-2
> 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
 

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

RE: Serving files from within Seaside

Boris Popov, DeepCove Labs (SNN)

We added the below to our components,

 

(html anchor)

callback: [self savePDF];

with: ‘Save PDF’

 

savePDF

                self

                                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;

                                                                                                yourself)].

-Boris

 

From: [hidden email] [mailto:[hidden email]] 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
 


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Solved: Serving files from within Seaside

jtuchel
In reply to this post by Karsten Kusche
Boris, Diego, Jon, Karsten,

Thanks a lot for your fast responses. The excellent news is that all of you agree on the very same solution, which makes it easy to judge whether that's the way to go.

But the even better news is that it works like a charm. So thanks and nice holidays!

Joachim
Reply | Threaded
Open this post in threaded view
|

Upload an download of large files (Re: [Seaside] Serving files from within Seaside)

Göran Krampe
In reply to this post by jtuchel
Hi!

As a sidenote - I have patches for Kom/Network/Iliad to do chunkwise
reading and writing of files directly onto disk. This means it can serve
(or upload) 1Gb+ files without even a blink of an eye and no image
growth at all. I also wrote a little test script that hammers a server
and verifies all files comes through with correct md5 sums.

If someone is very interested in this I can send over the snapshots - I
did this for a customer and they want it released upstream. I can try to
take some time to merge it in, but then it will not be done "now", but
if someone else wants to look at it - just tell me, because I am pretty
busy right now.

regards, Göran
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Upload an download of large files (Re: [Seaside] Serving files from within Seaside)

Philippe Marschall
On Wed, Dec 19, 2012 at 12:36 PM, Göran Krampe <[hidden email]> wrote:

> Hi!
>
> As a sidenote - I have patches for Kom/Network/Iliad to do chunkwise reading
> and writing of files directly onto disk. This means it can serve (or upload)
> 1Gb+ files without even a blink of an eye and no image growth at all. I also
> wrote a little test script that hammers a server and verifies all files
> comes through with correct md5 sums.
>
> If someone is very interested in this I can send over the snapshots - I did
> this for a customer and they want it released upstream. I can try to take
> some time to merge it in, but then it will not be done "now", but if someone
> else wants to look at it - just tell me, because I am pretty busy right now.

AFAIK, this has been merged quite some while ago.

Cheers
Philippe
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside