From d0bacc8988f99acb2e015e079a04423c928aa589 Mon Sep 17 00:00:00 2001 From: Drake Date: Fri, 13 Oct 2006 20:01:48 +0000 Subject: [PATCH] Make File assets work with the exporter. This means not using the streaming mechanism. This isn't optimal; should find a way to use the streaming mechanism iff we know that there's going to be a live HTTP session on the other end and not just a filehandle. --- lib/WebGUI/Asset/File.pm | 25 +++++++++++++++++++------ lib/WebGUI/Asset/File/Image.pm | 21 ++++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/lib/WebGUI/Asset/File.pm b/lib/WebGUI/Asset/File.pm index 3a90ca8f5..82bba6fc3 100644 --- a/lib/WebGUI/Asset/File.pm +++ b/lib/WebGUI/Asset/File.pm @@ -20,6 +20,7 @@ use WebGUI::Cache; use WebGUI::Storage; use WebGUI::SQL; use WebGUI::Utility; +use FileHandle; our @ISA = qw(WebGUI::Asset); @@ -371,14 +372,26 @@ sub www_edit { sub www_view { my $self = shift; return $self->session->privilege->noAccess() unless $self->canView; - if ($self->session->var->get("adminOn")) { - return $self->getContainer->www_view; +# if ($self->session->var->get("adminOn")) { +# return $self->getContainer->www_view; +# } + + # Kludge for now to make this work with the exporter. + my $path = $self->getStorageLocation->getPath($self->get('filename')); + my $fh = eval { FileHandle->new($path) }; + defined($fh) or return ""; + binmode $fh or ($fh->close, return ""); + my $block; + while (read($fh, $block, 16384) > 0) { + $self->session->output->print($block, 1); } - $self->session->http->setRedirect($self->getFileUrl); - $self->session->http->setStreamedFile($self->getStorageLocation->getPath($self->get("filename"))); - return '1'; + $fh->close; + return 'chunked'; + +# $self->session->http->setRedirect($self->getFileUrl); +# $self->session->http->setStreamedFile($self->getStorageLocation->getPath($self->get("filename"))); +# return '1'; } 1; - diff --git a/lib/WebGUI/Asset/File/Image.pm b/lib/WebGUI/Asset/File/Image.pm index 7cb7c66ae..3d16a444f 100644 --- a/lib/WebGUI/Asset/File/Image.pm +++ b/lib/WebGUI/Asset/File/Image.pm @@ -301,21 +301,20 @@ sub www_resize { } #------------------------------------------------------------------- - -=head2 www_view - -A web executable method that redirects the user to the specified page, or displays the edit interface when admin mode is enabled. - -=cut - +# Use superclass method for now. sub www_view { my $self = shift; - my $storage = $self->getStorageLocation; - $self->session->http->setRedirect($storage->getUrl($self->get("filename"))); - $self->session->http->setStreamedFile($storage->getPath($self->get("filename"))); - return "1"; + $self->SUPER::www_view; } +#sub www_view { +# my $self = shift; +# my $storage = $self->getStorageLocation; +# $self->session->http->setRedirect($storage->getUrl($self->get("filename"))); +# $self->session->http->setStreamedFile($storage->getPath($self->get("filename"))); +# return "1"; +#} + 1;