我的 Mojolicious 控制器中有一个子程序,当通过 http 帖子上传 csv 文件时调用它。上传文件后,会显示一条消息,上面写着“您将在 x 秒内被重定向”。所以我想实现 Mojo::IOLoop::Delay 并作为回调我使用重定向语句。但是我得到了 Morbo 的以下错误:
Mojo::Reactor::EV: Timer failed: Transaction already destroyed at /usr/local/share/perl/5.22.1/Mojolicious/Plugin/DefaultHelpers.pm line 168.
控制器代码:
sub upload {
my $self = shift;
# Check file size
return $self->render(text => 'File is too big.', status => 200)
if $self->req->is_limit_exceeded;
# Process uploaded file
return $self->redirect_to('/') unless my $newCsv = $self->param('fileToUpload');
my $size = $newCsv->size;
my $name = $newCsv->filename;
my $delay = 2;
$self->render(text => "Thanks for uploading $size byte file $name.<br>
You will be redirected in $delay seconds");
Mojo::IOLoop->timer($delay => sub {
$self->redirect_to('/');
});
}
相关路线:
$r->get('/')->to(controller => 'main', action => 'index');
$r->post('/uploadCsv')->to(controller => 'main', action => 'upload')->name('uploadCsv');
先感谢您