-my $first_chunk = 1;
-
-my $query;
-$query = new CGI \&upload_hook;
-$uploaded_file->done();
-send_reply('done', $uploaded_file->id());
-
-# FIXME - if possible, trap signal caused by user cancelling upload
-# FIXME - something is wrong during cleanup: \t(in cleanup) Can't call method "commit" on unblessed reference at /usr/local/share/perl/5.8.8/CGI/Session/Driver/DBI.pm line 130 during global destruction.
+my $upload = Koha::Upload->new( upload_pars($ENV{QUERY_STRING}) );
+if( !$upload || !$upload->cgi || !$upload->count ) {
+ # not one upload succeeded
+ send_reply( 'failed', undef, $upload? $upload->err: undef );
+} else {
+ # in case of multiple uploads, at least one got through
+ send_reply( 'done', $upload->result, $upload->err );
+}