[Seaside] How to set the mime-type of a response?
Ian Prince
ian at inextenso.com
Fri Oct 17 17:13:10 CEST 2003
Thanks Julian for all the options. I guess having so many options is an
illustration of the power behind Seaside.
I have implemented your second option for now, but have taken note of
the first which seems to be the more elegant and complete one (but a
little harder for a newbie like me to implement at this point in time).
Best regards,
Ian.
On Jeudi, oct 16, 2003, at 19:26 Europe/Zurich, Julian Fitzell wrote:
> Ian Prince wrote:
>> 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.
>
> Yeah, they would all be pulled in when you call #contents: I presume.
>
>> 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.
>
> Ok, I guess you have two choices. WADocumentHandler (which is the
> thing being added to handle the request from the user for that URL)
> expects a MIMEDocument which expects a String for its content. So you
> can't use that if you want to delay the reading of the file.
>
> First, assuming your PDF files are static, you could add another
> subclass of WARequestHandler that would hold, say a filename and a
> mime type and read the file in when the request came in. You'd want
> to write #hash and #= methods that use the filename and the mime type
> so that the browser can cache the requests. You might also want to
> look at using an MD5 hash of the file or something so it will detect
> if the file contents change (depending on whether this is an issue for
> you). Then look at WAHtmlRenderer#urlForDocument:mimeType: and use
> similar code but pass in one of your request handlers instead of a
> WADocumentHandler.
>
> Second option which doesn't make use of the cache and therefore is
> probably simpler if you're dynamically generating the files, would be
> to simply do something like:
>
> renderContentOn: html
> html
> list: batcher batch
> do: [:ea | html anchorWithAction: [self showPDF: ea] text: ea]
>
> showPDF: fileName
> self session returnResponse:
> (WAGenericResponse new
> contentType: 'application/pdf'
> nextPutAll: (self contentFor: fileName);
> yourself)
>
>
> Oh, actually you have three options. You could also serve the files
> from comanche or apache or something and just use static URLs to the
> files.
>
> Hope that gives you some direction. Shout if you need clarification.
>
> Julian
>
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside
>
More information about the Seaside
mailing list