Forum OpenACS Development: cr_write_content filename header

Collapse
Posted by Ryan Gallimore on
When cr_write_content serves a file, it doesn't seem to set an attachment filename header. Is this a bug? Should the filename be set to name of the cr item?
Collapse
Posted by Dave Bauer on
cr write content does not _know_ the filename. The caller needs to set the header. Lots of examples in the toolkit.
Collapse
Posted by Ryan Gallimore on
cr_write_content could look the filename up in cr_items.name if this is the convention in the toolkit. It seems to vary from acs-tcl to bug-tracker to file-storage.

I'm looking at acs-subsite/www/file.vuh - perhaps the header should be set there?

Collapse
Posted by Dave Bauer on
Yeah that makes sense, but probably better to let file.vuh handle it since cr_write_content is not necessarily only used to download a file. It can write HTML for example, which you don't want to be forced as a download.
Collapse
Posted by Ryan Gallimore on
cr_write_content has a storage type switch with text and file cases. The file case even sets another header already. I think it would be reasonable to set the filename header here so you don't have to remember to set it every time in the caller.
Collapse
Posted by Dave Bauer on
It sets the content size header due to a limitation on ns_returnfile.

There is no requirement that an item stores using filesystem storage have the original filename stored are cr_items.name, so you can't reliably set the attachment header with the correct download filename unless you know how you stored it.

The file.vuh handler deals with this by allowing a filename to be appended to the URL ie:

/file/12345/example.doc

the image vuh handler also allows this.

In this way the code that generates the URLs, if it has the correct filename information, can set the URL with the proper filename.

I don't really have a strong opinion either way, but automatically setting the attachment header is cr_write_content will most likely cause some unexpected behavior somewhere.

Collapse
Posted by Ryan Gallimore on
Thanks Dave, I didn't notice the filename could be included in the URL.