I have used a similar solution, and the headers printed by the applications 
when downloading with LWP's
get -e "[url]"
are the following:

Connection: close
Date: Fri, 23 Feb 2007 21:27:06 GMT
Server: Apache/2.2.4 (Unix) mod_apreq2-20051231/2.6.0 mod_perl/2.0.3 Perl/v5.8.8
Content-Length: 72934
Content-Type: text/comma-separated-values
Client-Date: Fri, 23 Feb 2007 21:28:20 GMT
Client-Peer: 81.196.156.249:80
Client-Response-Num: 1
Content-Disposition: attachment;filename="REGS--2007-01-24-2007-02-23.csv"
Set-Cookie: brk=113bef15c5f8b6727bb01a5586760abda3d1e0c7; 
domain=.tranzactiibursiere.ro; path=/
X-Catalyst: 5.7006

But the browser doesn't allow downloading that file when clicking on the link 
then choosing "save". It allows downloading it when right-clicking and choosing 
"Save as...".

Does anyone have any idea what could be wrong (with these headers or something 
else)?

Thanks.

Octavian

  ----- Original Message ----- 
  From: vb 
  To: The elegant MVC web framework 
  Sent: Friday, February 23, 2007 4:38 PM
  Subject: Re: [Catalyst] displaying csv content


  A solution for CSV from Catalyst I used time ago:

  sub down_san : Local {
       my ($self, $c) = @_;
       my $sc = $c->session->{scoala};
       my $lu = $c->session->{stag0};
       my $lnu = $lu->nume; my $ln = $lnu; $ln =~ s/-..$//; $ln = $ml{$ln}; 
       my $an = $lnu; $an =~ s/^...-//; $an = '20' . $an;
       my @ang = salar::Model::State->angsclu($sc->id, $lu->id);
       my $csv = Text::CSV_XS->new({binary => 1});
       my $out = ""; my @h = (); my $f = $an."-".$ln."- sanatate.txt";
       @h = ('Nume-Prenume','CNP','Brut-san','CASS'); 
       $csv->combine(@h);
       $out .= $csv->string . "\n";
       foreach my $g (@ang) {
  # don't use diacritics in Romanian institutions!
          my $nume = $g->id_angajat->nume . ' ' . $g->id_angajat->pren;
          utf8::decode($nume);
          $nume =~ s/([ăşţîâĂŞŢÎÂ])/$DIACRITICE{$1}/eg; $nume = uc($nume); 
          my @w = ();
          push @w, $nume; push @w, $g->id_angajat->cnp;
          push @w, $g->bsan; push @w, $g->isan;
          $csv->combine(@w);
          $out .= $csv->string . "\n"; 
       }
       $c->res->headers->header('Content-Type' => 'text/csv');
       $c->res->headers->header('Content-Disposition' => 
"attachement;filename=$f");
       $c->res->body($out);   
  }

  --vlad


  On 2/23/07, Octavian Rasnita <[EMAIL PROTECTED]> wrote: 
    Hi,

    Can anyone point me to a place where I can find how to send csv content to 
    the browser correctly?

    If I right click on the link and choose save as... the content is saved
    correctly, and the file name specified by Content-Disposition appears
    correctly, but if I just click on the link, it appears a window that asks 
me 
    if I want to open or save it, and if I choose "save", nothing happends, and
    that window don't ask me for a file name.

    I know that the http headers might be wrong, but I don't know the right way 
    of sending them.

    Do I need to create another view, or I need to change something in the end()
    subroutine?

    Thanks.


    Octavian


    _______________________________________________
    List: [email protected]
    Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
    Searchable archive: http://www.mail-archive.com/[email protected]/
    Dev site: http://dev.catalyst.perl.org/





------------------------------------------------------------------------------


  _______________________________________________
  List: [email protected]
  Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
  Searchable archive: http://www.mail-archive.com/[email protected]/
  Dev site: http://dev.catalyst.perl.org/
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to