Forum OpenACS Q&A: Bboard attachments

Collapse
Posted by Diego Manilla on
Hi!

It seems to exist a little problem with Bboard attachments. When I right-click on a Bboard attachment and choose to "Save link target as", the default name of the file to save is always "attachment.txt", the real name of the file (and its extension) doesn't matter. Is there any possibility that the real name of the file appears as default?

I'm using OACS 4.5-PG 7.1.3

thanks.

Collapse
2: Re: Bboard attachments (response to 1)
Posted by Vadim Makarov on
I don't have a solution, but here are a couple leads.

The browser just takes the text between the last slash sign and the first question sign in the URL, and thinks it is the filename (possibly adding an extension according to the specified MIME encoding). To make sure this text is your filename, you'd need to modify the message display code that produces links to attachments to link to e.g. .../attachment_m/filename?file_id=..., and then make the request processor recognize it and turn it into .../attachment?file_id=... The latter you can probably do via attachment_m.vuh, but I've never done the .vuh stuff and can't explain this part. Can anyone help?

Another possibility is to add a "Content-Disposition" header when the bboard serves the attachment. Find and modify the code that serves the attachment, to include a suitably formed header into the output. I'm afraid, however, this method can lead to incompatibility and strange behaviour in some browsers, e.g. always offering to save the attachment instead of displaying it, wrong file type etc.

I'd prefer the first method that puts the right filename into URL. It works in Netscape 4.7, so it must be trouble-free in all other browsers too :)

Collapse
3: Re: Bboard attachments (response to 2)
Posted by Diego Manilla on
Thanks Vadim, your comments have been very useful. I didn't know the exact behavior of vuh files, but after taking a look at the docs (Virtual URL Handlers section) it has been really easy to do what you suggested (the first option). I only needed to create a subdir in /packages/bboard/www with an index.vuh inside as simple as

ad_page_contract {
	serve bboard attachment
} {
    file_id:integer,notnull
}

ad_returnredirect "../attachment?file_id=$file_id"

... and modify the attachments link to make it appear with the real name of the file.

It works, at least with the couple of files that i've tested sing Mozilla 1.0.

You suggested to create an attachments_m.vuh file, but i read here in the forums that only the index.vuh works (at least in OACS 4.5), although i haven't tested that.

But... there's still one problem: the files with spaces in their file name. A file called "my file.swx" will appear in the save as dialog as "my%20file.swx", and i'm afraid this has no possible solution, hasn't it?

regards

Collapse
4: Re: Bboard attachments (response to 1)
Posted by Vadim Makarov on
If spaces are in the link (i.e. they are not replaces by %20 in the HTML source), the behaviour depends on the browser. NN4 will fail, IE5 and IE6 will save with %20, Moz1.3 and Opera5 will save correctly.

If you think this must be rectified, you'd probably have to use "Content-Disposition" header and test across browsers that its use doesn't create other problems.

<rant>
Allowing spaces in filenames was one of the marketing decisions Microsoft should be hated for, because it has created lots of compatibility gotchas not obvious to the typical user until he stumps into them... even with current MS software.
<rant>

Collapse
5: Re: Bboard attachments (response to 1)
Posted by David Walker on
I normally replace space with underscore for the file name and then if I need to display a pretty name I will replace the underscore with a space.
Collapse
6: Re: Bboard attachments (response to 5)
Posted by Tilmann Singer on
Diego, there was an error with the rp not recognizing .vuh files named other than index.vuh, which should be fixed in the more recent oacs-4-6 and HEAD versions. In 4.5 it's most likely broken.

Are you using sdm.openacs.org because it contains older versions of the documentation? Otherwise you might want to use https://openacs.org/doc/openacs-4/rp-design.html instead.

Also instead of ad_returnredirect you might want to use rp_internal_redirect together with rp_form_put - I wonder why the first one works at all, and doubt that it will have the desired effect on all browsers.

Collapse
7: Re: Bboard attachments (response to 1)
Posted by Diego Manilla on
Vadmin, i've taken a look at "Content-Disposition" as you suggested and now i have the bboard attachments working as i wanted, returning the correct name of the file.

In ReturnHeaders proc (called by cr_write_content, the proc used by bboard to write attachments back to user) i added the line

Content-Disposition: attachment; filename=$filename

David, using underscores was not an option that satisfied us, buth thanks anyway.

And Tilmann, the link i put pointing to sdm.openacs.org was the result of a search in Google (vuh openacs, i think), i don't usually read the docs stored there, but thanks for the advice.

Thanks again

Collapse
8: Re: Bboard attachments (response to 1)
Posted by Diego Manilla on
I thought that everything was solved but another problem exists... the words with accents, ñ's, ... I suppose that it's due to the encoding charset of the HTTP headers (because now the name of the file it's on the headers), is it possible to specify it?

I've tried with "charset=iso8859-1" but it doesn't work because this parameter refers to the contents and not the header itself.

I've also tried almost every possible use of convertto and convertfrom tcl functions.

I've also used several AOLServer params, such as PreferredCharsets, DefaultCharset, HttpOpenCharset, OutputCharset or SystemEncoding.

Any possible solution?

thanks