Forum OpenACS Development: cr_write_content and file return...

Collapse
Posted by Jeff Davis on
I noticed that thumbnails were not being cached from photo-album and tracked it down to the call in cr_write_content which calls ns_cpfp to return the filesystem file. If I change cr_write_content to look like
switch $storage_type {
        text { 
            ReturnHeaders $mime_type
            ns_write [db_string write_text_content ""]
        }
        file {
            set path [cr_fs_path $storage_area_key]
            set filename [db_string write_file_content ""]
            ns_returnfile 200 $mime_type $filename
        }
        lob  {
            ReturnHeaders $mime_type
            db_write_blob write_lob_content ""
        }
    }
and I now get 304s for unchanged files. This is not 100% safe since the revision file timestamp is not necessarily the timestamp you should use for the item but it seems like we should make cr_write_content pay attention to if-modified-since headers and I think it should be pretty straightforward to do so. Does anyone have any objection?
Collapse
Posted by Jun Yamog on
Hi Jeff,

No objection its better than what we currently have.  But I believe someone brought this up in the bboards a few weeks ago.  And he/she also made some changes.  It would be nice if that someone will post here what he/she did.

Collapse
Posted by Don Baccus on
I have no objection.  I wrote this routine but all I did was to bundle up code from the file storage package into a convenient utility (every package returning a file duplicated this functionality at the time).
Collapse
Posted by Peter Alberer on
I posted the same issue a few weeks ago and supposed to change the code in db_write_blob. But doing the ns_returnfile immediately in cr_write_content is probably the better solution. Anyway i think its good to do this change as like Jeff mentioned, attention should be payed to if-modified-since headers.
Collapse
Posted by Jamie Rasmussen on
There are related problems in db_exec_lob and cr_create_content_file.  Several of the file upload problems people have had with Win32 OpenACS occur because file handles aren't fconfigure'd with "-translation binary" before use.

See JCD's comment in cr_create_content_file - TCL's file copy really would be better than ns_cpfp.  Peter's changes to use ns_returnfile in db_exec_lob should fix the other problems - I've just been adding the fconfigure where necessary, but the proposed solution increases efficiency too.