[cgiapp] redirect/content type

Benjamin Hitz hitz at genome.stanford.edu
Thu Jun 12 13:49:47 EDT 2008


This works awesomely.  Thanks.  Just to point out for anyone following  
along, because I was a little confused about "content-disposition" -  
you do not have to have such a file "$filename" on the server... it's  
just a made up file name for the client, which is exactly what I wanted.

Ben


> Hi Ben,
>
> We have a runmode that does almost exactly what you want. It lets  
> the user download a csv file onto their PC with the correct  
> filename. The code we use is below.
>
>   $self->header_props( -type => 'text/csv' );
>   $self->header_add( '-content-disposition' => "attachment; filename= 
> $filename" );
>
> Regards,
>
> *DAVID BAXTER*
>
> *  SiteSuite Australasia*
> Websites Made Easy
> Tel: 61 2 9213 0500
> Fax: 61 2 9212 5161
> Email: david at sitesuite.com.au <mailto:david at sitesuite.com.au>
> Web: www.sitesuite.com.au <http://www.sitesuite.com.au/>
>
>
>
>
> Benjamin Hitz wrote:
>>
>> This is probably a vanilla CGI question, but I am working under  
>> CGIapp so here goes.
>>
>> I have a cgi::app that shows a table.  I want to have a link which  
>> generates a plain text (tab delim) version of the table, and pops  
>> up a "save as" window.
>>
>> Prior to cgi-app we just wrote a temp file on the server, and added  
>> a link to it - this doesn't set the correct MIME type so if you  
>> click on it it shows you the file in the browser (not what you want  
>> usually).
>>
>> I have a run mode in my cgi-app to generate the file, but I seem to  
>> have two mildly unsatisfying option:
>>
>> 1) write a tmp file on the server, and use redirect to get the txt  
>> file... but I cannot seem to sent the Content-Type: on the redirect  
>> (I even tried faking the header in the txt file).
>>
>> 2) change the header with $self->header('-type' -> 'application/ 
>> octet-stream') and return the text in the run mode.  This gives me  
>> the "download" option (MIME type set correctly) but the file name  
>> appears as "myscript.pl" and says it's a perl source.
>>
>> Some way to set BOTH a redirect and a content-type?   Or simply  
>> fake the name name of the file?
>>
>> Thanks,
>>
>> Ben
>> -- 
>> Ben Hitz
>> Senior Scientific Programmer ** Saccharomyces Genome Database ** GO  
>> Consortium
>> Stanford University ** hitz at genome.stanford.edu
>>
>>
>>
>>
>> #####  CGI::Application community mailing list  ################
>> ##                                                            ##
>> ##  To unsubscribe, or change your message delivery options,  ##
>> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
>> ##                                                            ##
>> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
>> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
>> ##                                                            ##
>> ################################################################
>>
>>
>>
>>
>
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################

--
Ben Hitz
Senior Scientific Programmer ** Saccharomyces Genome Database ** GO  
Consortium
Stanford University ** hitz at genome.stanford.edu





More information about the cgiapp mailing list