Forum OpenACS Development: Extending the Content Repository (CR) TCL API.


At the moment (OpenACS 5.3.0) the upload a file the CR TCL API offers the function: content::item::upload_file

But if you create a folder and a custom content_type is registered to the folder (content::folder::register_content_type), then isn't possible to use the function content::item::upload_file, to upload a file under the folder, because the function doesn't have a switch in order to pass the custom content_type. The solution is to use the "low level" function cr_import_content (in fact the function is used inside of content::item::upload_file) , that has the switch -other_type in order to manage custom content_types.

In order to access to the CR in a consistent way, It is possible to add a switch to content::item::upload_file to manage a custom content_type?

An example of the new code for content::item::upload_file could be:

ad_proc -public content::item::upload_file {
{-package_id ""}
{-other_type "content_revision"}
} {
Store the file uploaded under the parent_id if a file was uploaded

@author Malte Sussdorff (
@creation-date 2005-06-21

@param upload_file

@param parent_id

@param other_type

@return the revision_id of the generated item

} {

set filename [template::util::file::get_property filename $upload_file]
if {$filename != "" } {
set tmp_filename [template::util::file::get_property tmp_filename $upload_file]
set mime_type [template::util::file::get_property mime_type $upload_file]
set tmp_size [file size $tmp_filename]
set extension [file extension $filename]
if {![exists_and_not_null title]} {

set title $filename

set existing_filenames [db_list get_parent_existing_filenames {}]
set filename [util_text_to_url \
-text ${title} -existing_urls "$existing_filenames" -replacement "_"]

set revision_id [cr_import_content \
-storage_type "file" -other_type $other_type -title $title -package_id $package_id $parent_id $tmp_filename $tmp_size $mime_type $filename]

content::item::set_live_revision -revision_id $revision_id

return $revision_id

Thanks for the help!


Posted by Jorge Couchet on
Well, the function cr_import_content is in the TCL API too. But the logical idea (of course in my mind) is to search all the CR functions under "content::", and these is the meaning of "In order to access to the CR in a consistent way".

Thanks again!


Posted by Dave Bauer on

content::item::new with the -tmp_filename switch.

It is the new and improved (and consistent) way to store uploaded content in the CR.

Posted by Jorge Couchet on

Thanks a lot!