views:

83

answers:

3
+2  Q: 

How to serve .RTFs

I support a web-application that displays reports from a database. Occassionally, a report will contain an attachment (which is typically an image/document which is stored in the database as well).

We serve the attachment via a dynamic .htm resource which streams the attachment from the database, and populates the content-type based on what type of attachment it is (we support PDFs, RTFs, and various image formats)

For RTFs we've come across a problem. It seems a lot of Windows users don't defaultly have an assocation for the 'application/rtf' content-type (they do have an association for the *.rtf file extention). As a result, clicking on the link to the attachment doesn't do anything in Internet Explorer 6.

Returning 'application/msword' as the content-type seems to make the RTF viewable when clicking on the link, but only for people who have MS Office installed (some of the users won't have this installed, and will use alternate RTF readers, like OpenOffice).

This application is accessed publicly, so we don't have control of the user's machine settings.

Has anybody here solved this before? And how? Thanks!

A: 

Wordpad (which is on pretty much every Windows machine) can view RTF files. Is there an 'application/wordpad' content-type?

Alternatively, given the rarety of RTF files, your best solution might be to use a server-side component to open the RTF file, convert it to some other format (like PDF or straight HTML), and serve that to the requesting client. I don't know what language/platform you're using on the server side, so I don't know what to tell you to use for this.

MusiGenesis
+3  A: 

Use application/octet-stream content-type to force download. Once it's downloaded, it should be viewable in whatever is registered to handle .rtf files.

Matthew Scharley
One more thing I forgot to mention: we'd ideally like to have the documents displayed within a frame in the browser (instead of being downloaded).Having Office 2003 installed seems to open application/msword documents within the browser fine, but Office 2007 seems to cause the document to default open within a new instance of MS Word. However, this is client side behaviour that we can't control, so out of the scope for our web app.
pikachow
Another problem is that the resource that returns the content is a *.htm, so downloading it with a *.htm extension won't let the users open it without renaming the file (our user base won't necessarily be so technical).We could dynamically change the extention in the resource name based on the attachment type, but we only intend to display these attachments within the browser anyway, so we don't really need to cater for that use case.
pikachow
Word is the only (client-side) application that I know of that will display an RTF inside the browser. You're only other option is to convert it to HTML/PDF and display that (probably HTML though, given the extension issue)
Matthew Scharley
+2  A: 

In addition to the Content-Type header, you also need to add the following:

Content-Disposition: attachment; filename=my-document.rtf
too much php