[Seaside] How to set the mime-type of a response?

Ian Prince ian at inextenso.com
Thu Oct 16 13:28:30 CEST 2003


Hi Julian and Brian,

	thank you both for your quick responses.

I have implemented Julian's suggestion - works like a charm.

OTOH, I did manage to freeze my image when calling 
anchorWithDocument:mimeType:text: v as follows

	html
		list: batcher batch
		do: [:ea | html
				anchorWithDocument: (self contents: ea)
				mimeType: 'application/pdf'
				text: ea].

where the batcher is on a file directory with some very large pdf files.

It seems like all the Documents in the batched list are "created" in 
memory.

How can I avoid this issue, i.e delay creating the documents until the 
user actually clicks on a document link?

I get the feeling the answer is simple - I just can't quite see it at 
this stage in my Seaside newbie-ness.

Thanks in advance.

Ian.



On Mercredi, oct 15, 2003, at 19:00 Europe/Zurich, Julian Fitzell wrote:

> Hi Ian,
>
> What you probably want to do is create the link to the document by 
> calling #anchorWithDocument:mimeType:text: or 
> #anchorWithDocument:text: on WAHtmlRenderer.  You could, for example, 
> have a render method like:
>
> renderContentOn: html
> html
> 	anchorWithDocument: self myFileContents
> 	mimeType: 'application/pdf'
> 	text: 'Download my PDF'
>
> It looks like whatever object you pass in as the document needs to 
> implement asMIMEDocument, which at the moment seems to limit it to 
> Strings, Forms, and Images.  I imagine it could be implemented for 
> other things like Streams, but it would just have its contents pulled 
> out at that point anyway.  The additional benefit of this method is 
> that the document is cached so if it is downloaded again the browser 
> will be able to use its cached version.  This is based on content so 
> as soon as the document is changed it will have a different ID and 
> will get downloaded again.
>
> Julian
>
> Ian Prince wrote:
>> Hello All,
>> I have been following Seaside since 0.91 and it reminds me of Bobo 
>> back in 1998 before it became Zope - wonderfully simple and elegant.
>> Anyway here's my first question: I am trying to return the contents 
>> of a file read from disk (or created on the fly) but can't find out 
>> how to set its mime-type.
>> In Zope/DTML I think this would be as follows for a PDF document:
>>     <dtml-call "RESPONSE.setHeader('Content-Type', 
>> 'application/pdf')">
>> How can I do this in Seaside (I'm using Seaside2.3b5.st)?
>> My apologies if I'm missing something very obvious.
>> Thanks in advance,
>> Ian.
>> -- 
>> ian prince - inextenso - 1 ruelle des moulins - 1260 nyon - 
>> switzerland
>> ian at inextenso.com - tel +41 22 990 10 80 - mobile +41 78 880 27 02
>> _______________________________________________
>>

On Mercredi, oct 15, 2003, at 19:02 Europe/Zurich, Brian Brown wrote:

> On Wednesday, Oct 15, 2003, at 10:31 America/Denver, Ian Prince wrote:
>
>> Hello All,
>>
>> I have been following Seaside since 0.91 and it reminds me of Bobo 
>> back in 1998 before it became Zope - wonderfully simple and elegant.
>>
>> Anyway here's my first question: I am trying to return the contents 
>> of a file read from disk (or created on the fly) but can't find out 
>> how to set its mime-type.
>>
>> In Zope/DTML I think this would be as follows for a PDF document:
>>
>> 	<dtml-call "RESPONSE.setHeader('Content-Type', 'application/pdf')">
>>
>
> This cracks me up :-) I used to do that as well.
>
>
>> How can I do this in Seaside (I'm using Seaside2.3b5.st)?
>
> I think you should check out WAFile, and I have also implemented an 
> asMIMEDocument message on custom  images and audio files looking 
> something like this:
>
> asMIMEDocument
> 	^ MIMEDocument contentType: 'image/jpeg' content: self contents
>
>
> You could do exactly the same thing... the text of a pdf document in 
> an ivar, and just change the above mime type to 'application/pdf'. You 
> would call it like this:
>
> myPDFCollection do:
> 	[:ea  |
> 	html anchorWithAction: [self answer: ea] text: ea pdfName]
>
> ...assuming your PDF object had a pdfName method.
>
> Anyway, I hope that helps.
>
> Brian



More information about the Seaside mailing list