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 |
Hi Joachim,
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
_______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
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 |
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 |
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 |
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
_______________________________________________ seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
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 |
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 |
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 |
Free forum by Nabble | Edit this page |