Sending files question

Help
2013-01-03
2013-05-28
  • LordPraslea
    LordPraslea
    2013-01-03

    Hi.

    I remember a few months ago I came across a page entitled "Sending Files and Non-HTML Data" in the mini tutorial you wrote.
    ON that same day I  tried something similair to this.. but I've failed to find any channel or possibility to post non-html files..

    This code snippet however does give you a file.. but it contains html..
    Any ideea how to implement it from within the controller or I have to dig deep into WOOF to modify/add functionality?

    oo::define DownloadController {
        method file {} {
            ##use this to download a file :D
            set fileName test.txt
            #the file location must be ABSOLUTE!
            #set fileLocation [file dirname [web::config script]]/$fileName
            set fileLocation $fileName
            #Send it as an attachment, including the file name, this may vary
    
            #woof::Response create response
            response headers set  Content-type application/octet-stream 
            response headers set  Content-Disposition "attachment; filename=$fileName" 
            response headers set Content-Transfer-Encoding binary  
            #response headers set Content-Length  [file size $fileLocation]
            response headers set  Cache-control private
        
            if {0} {
            #open  & read the file
            set fp [open $fileLocation  r]
            set size [file size $fileLocation]
            set file_data [read $fp $size]
            close $fp
            ##send the data to the browser
            }
        }
    }
    
     
  • Sadly, I have not had much time to work on woof, open source attention having been elsewhere. I had intended to add this at some point, however it was of low priority because my thought was that files should not go through woof at all for efficiency reasons as well as having to generate the right mime headers. Since the web servers already have that intelligence built in (not bowwow, which is a toy for now, based on wibble, but real web servers), the URL's you provide for files should be mapped by the web server's config directly without going through woof. The web server will then serve them with the correct mime types and without bothering woof.

    Hope that makes sense. Else let me know and I'll see if how hard it would be to add that support in.

    /Ashok