ted.byers has asked for the wisdom of the Perl Monks concerning the following question:
I used your search engine and nothing since 1999 included all four keywords in either the text or title.
I used the following to create and send a csv file, from a specialized CGI script.
my $a_ref = $dbh->selectall_arrayref($sql); my @a = @$a_ref; print $cgi->header(-type=>'text/csv', -charset=>'utf-8', -attachment=>'data.csv'); print "Platform ID, Processor ID, Transaction ID, Date, Settlement Dat +e, Transaction type, Status, Amount, First Name, Last Name,Address1,A +ddress(cont.),City,State or Province,Postal Code,Country, Phone, Emai +l, Processor response code, MSC response code, IP Address, CC Number, +Descriptor\n"; foreach my $v (@a) { my ($m_id,@r) = @$v; $r[6] = ($r[6]) ? 'succeeded' : 'failed'; foreach my $tv (@r) { $tv = '' unless defined $tv; } push @r,$descriptors{$m_id}{$r[0]}; print join(',',@r),"\n"; } $dbh->disconnect;
This code works perfectly as long as the CSV file is less than approximately 152 kB! Alas, if the CSV file is greater than about 152 kB, the first 152 kB is sent, and the rest discarded, so the user sees a truncated file. NB: I used "-attachment=>'data.csv'" so that the client browser would have a name to assign to the file received, as the data is coming from a SQL query rather than a real file.
I tried adding "-Content_length=>$len," to the header section, and instead of printing the rows as I iterate through them, I put the content into a really long string, '$s', used length($s) to get a value for the content length, and again, it all works perfectly as long as the csv file size is less than about 152kB, but in this case, the file is never sent at all if the file size is greater than 152 kB.
Where is the 152 kB limit coming from, and how can I over-ride that limit, if that is possible? Or do I have to actually create the file somewhere in the document root dirctory tree, and issue a redirect or forward. If I have to resort to the latter, how do I ensure that the file is deleted once the client has it, or that no one else can ses the file?
I am almost at the point of either placing a limit on the amount of data that can be requested, or putting the data into a zip archive and downloading the archive, with the best available compression, instead of the csv file, but that smells like a bad kludge, especially since the user no longer has the option of just opening the csv file in his spreadsheet software once his browser has it.
Thanks
Ted
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: csv file download size limits?
by talexb (Chancellor) on Nov 07, 2013 at 20:25 UTC | |
by ted.byers (Monk) on Nov 07, 2013 at 21:44 UTC | |
by hippo (Archbishop) on Nov 07, 2013 at 22:23 UTC | |
by ted.byers (Monk) on Nov 08, 2013 at 15:35 UTC | |
|
Re: csv file download size limits?
by Tux (Canon) on Nov 08, 2013 at 07:35 UTC | |
by ted.byers (Monk) on Nov 08, 2013 at 15:47 UTC | |
|
Re: csv file download size limits (not perl)
by Anonymous Monk on Nov 08, 2013 at 00:27 UTC |