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.
This commit is contained in:
Drake 2006-10-13 20:01:48 +00:00
parent dc5d96dd5b
commit d0bacc8988
2 changed files with 29 additions and 17 deletions

View file

@ -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;

View file

@ -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;