This question about Installation of Foswiki, Using an extension: Task closed

File Upload error / Undefined subroutine &Foswiki::decode_utf8

We are experiencing troubles with file uploads. File upload seems completely broken in Foswiki 1.1.9 in our setup. We recently moved our Foswiki-application to a new server and since then, we cannot upload files anymore. In the frontend, we get the following error when trying to upload any file:

Either you did not specify a file name, or the file you are trying to upload screenshotaufloesung.png has no content. You may not upload an empty file.

In the error-log we get:
Undefined subroutine &Foswiki::decode_utf8 called at /var/www/foswiki/lib/Foswiki/Engine/Apache.pm line 217.
 at /var/www/foswiki/lib/Foswiki/Engine/Apache.pm line 217.
   Foswiki::Engine::Apache::prepareUploads('Foswiki::Engine::Apache2::MP20=HASH(0x7fcbe54c4398)', 'Foswiki::Request=HASH(0x7fcbe474c098)') called at /var/www/foswiki/lib/Foswiki/Engine.pm line 76
   Foswiki::Engine::__ANON__() called at /var/www/foswiki/lib/CPAN/lib/Error.pm line 379
   eval {...} called at /var/www/foswiki/lib/CPAN/lib/Error.pm line 371
   Error::subs::try('CODE(0x7fcbe474b888)', 'HASH(0x7fcbe474be40)') called at /var/www/foswiki/lib/Foswiki/Engine.pm line 122
   Foswiki::Engine::prepare('Foswiki::Engine::Apache2::MP20=HASH(0x7fcbe54c4398)') called at /var/www/foswiki/lib/Foswiki/Engine/Apache.pm line 87
   Foswiki::Engine::Apache::run('Apache2::RequestRec=SCALAR(0x7fcbe473dd80)') called at -e line 0
   eval {...} called
CGI -any pragma has been REMOVED. You should audit your code for any use of none supported / incorrectly spelled tags and remove them at /usr/local/share/perl/5.18.2/CGI.pm line 926.

The code on lib/Foswiki/Engine/Apache.pm causing the problematic call on line 217 looks like this:

 if ( $this->{query}->isa('CGI') ) {
        foreach my $key ( keys %{ $this->{uploads} } ) {
            my $fname = $this->{query}->param($key);
            my $ufname = Fowswiki::decode_utf8($fname);
            $uploads{$ufname} = new Foswiki::Request::Upload(
                headers => $this->{query}->uploadInfo($fname),
                tmpname => $this->{query}->tmpFileName($fname),
            );
        }
    }

So there is a call to Foswiki::decode_utf8, but in Foswiki.pm I cannot find any function called decode_utf8. I tried changing

Foswiki::decode_utf8

to

Engine::decode_utf8

which does indeed not cause the error message anymore, but the file upload fails with the same message anyway.

My Perl version:

perl -v: This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi

Any ideas what's going on here? We upgraded from 1.1.8 to 1.1.9 some time ago, but that did not seem to cause any troubles. Thanks for any suggestions!


By any chance have you upgraded extensions to the latest versions, possibly the ModPerlEngineContrib? Foswiki::decode_utf8 is new with Foswiki 2.x, so it appears that we missed some backwards compatibility checks. I'd recommend downgrading that extension. If you used the extensions installer to update, then there should be a backup of the older versions in the working/configure/backup directory.

-- Main.GeorgeClark - 15 Jan 2016 - 15:14

Actually, this patch might solve the issue. I don't have a mod_perl system to quickly test it on though. If it works, please let us know.

diff --git a/ModPerlEngineContrib/lib/Foswiki/Engine/Apache.pm b/ModPerlEngineContrib/lib/Foswiki/Engine/Apache.pm
index 4d1338e..13b37c8 100644
--- a/ModPerlEngineContrib/lib/Foswiki/Engine/Apache.pm
+++ b/ModPerlEngineContrib/lib/Foswiki/Engine/Apache.pm
@@ -214,8 +214,11 @@ sub prepareUploads {
     my %uploads;
     if ( $this->{query}->isa('CGI') ) {
         foreach my $key ( keys %{ $this->{uploads} } ) {
-            my $fname  = $this->{query}->param($key);
-            my $ufname = NFC( Foswiki::decode_utf8($fname) );
+            my $fname = $this->{query}->param($key);
+            my $ufname =
+              ($Foswiki::UNICODE)
+              ? NFC( Foswiki::decode_utf8($fname) )
+              : $fname;
             $uploads{$ufname} = new Foswiki::Request::Upload(
                 headers => $this->{query}->uploadInfo($fname),
                 tmpname => $this->{query}->tmpFileName($fname),
@@ -225,11 +228,14 @@ sub prepareUploads {
     else {
         foreach my $key ( keys %{ $this->{uploads} } ) {
             my $obj = $this->{query}->upload($key);
-            $uploads{ NFC( Foswiki::decode_utf8( $obj->filename ) ) } =
-              new Foswiki::Request::Upload(
+            my $ufname =
+              ($Foswiki::UNICODE)
+              ? NFC( Foswiki::decode_utf8( $obj->filename ) )
+              : $obj->filename;
+            $uploads{$ufname} = new Foswiki::Request::Upload(
                 headers => $obj->info,
                 tmpname => $obj->tempname,
-              );
+            );
         }
     }
     delete $this->{uploads};

-- GeorgeClark - 15 Jan 2016

Your patch seems to work! Thanks for the quick help! Yes, you guessed correctly, the Server is using mod_perl and had ModPerlEngineContrib installed.

-- MichaelHelwig - 18 Jan 2016

Hello guys. I have a very similar problem. I am using FOSWIKI 2.0.1 branch, ubuntu 16.04 and mod_perl

I see that the patch George Clark made into the Master and 2.0.1 branch, but even though the error message on the browser is the same: "Either you did not specify a file name, or the file you are trying to upload screenshotaufloesung.png has no content. You may not upload an empty file." On the error_log file it is different:

[Fri Dec 9 08:40:33 2016] upload: Use of uninitialized value $fname in hash element at /var/www/foswiki/core/lib/Foswiki/Request.pm line 734. [Fri Dec 9 08:40:33 2016] upload: Use of uninitialized value in hash element at /var/www/foswiki/core/lib/Foswiki/Request.pm line 704.

-- CobraKoral - 09 Dec 2016

Guys, this issue is fixed already, you can close this task.

Thanks!

-- CobraKoral - 09 Feb 2017
 

QuestionForm edit

Subject Installation of Foswiki, Using an extension
Extension ModPerlEngineContrib
Version Foswiki 1.1.9
Status Task closed
Related Topics Tasks.Item13926
Topic revision: r7 - 09 Feb 2017, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy