Wild guess (based on comparing your code to my upload code). Instead of
## pull the file in a variable
my $fh = $query->upload('upload');
## determine the file type via the headers
my $type = $query->uploadInfo($fh)->{'Content-Type'};
try
## pull the filename in a variable
my $fname = $query->param('upload');
## determine the file type via the headers
my $info = $query->uploadInfo($fname);
my $type = $info->{'Content-Type'};
I take an extra step, but found that having
$info where I could get at it with the debugger paid off (once, which was enough).