You are here: Foswiki>Tasks Web>Item13867 (03 Feb 2016, GeorgeClark)Edit Attach

Item13867: bin/upload failed fron the command line

Priority: Enhancement
Current State: Closed
Released In: 2.1.0
Target Release: minor
Applies To: Engine
Branches: master Item13699
Reported By: JeanPhilippeRutault
Waiting For:
Last Change By: GeorgeClark
When using upload from the command line:

./upload filepath="/tmp/test.txt" filename="test.txt" topic=Sandbox.TestTopic

the execution failed with the following error:

Either you did not specify a file name, or the file you are trying to upload /tmp/test.txt has no content. You may not upload an empty file.

I would use this in a script which collect report on various servers and attach the reports to a topic to track down history of the generated report. As a workaround (not tested so far, suggested by @gac410 on #fowiki) I can use

-- JeanPhilippeRutault - 24 Nov 2015

I get the same error, but also on Foswiki 1.1.7 and 1.1.9, I've also gone back to older perl 10.1, and CGI 3.43. Still fails. Is there any chance that someone patched your system? Or is it something other than 1.1.9?

-- GeorgeClark - 24 Nov 2015

I've gon all the way back to Foswiki 1.0.9, and it still fails with an error. The Foswiki upload script uses the facilities of CGI to determine the file type (content-type header). No headers are passed in CLI calls to foswiki, so this information just isn't there. If you have this working, could you please compare your lib/Foswiki/Engine/ with the one shipped with 2.0?

I believe the solution will be to have the CLI engine process the upload files, but the code doesn't exist currently.

-- GeorgeClark - 24 Nov 2015

Sorry, I didn't mention that I used Foswiki 2.0.1.

-- JeanPhilippeRutault - 25 Nov 2015

The fix is pretty simple. Would probably fit Foswiki 1.1 as well.
diff --git a/core/lib/Foswiki/Engine/ b/core/lib/Foswiki/Engine/
index 9653c38..eb702cd 100644
--- a/core/lib/Foswiki/Engine/
+++ b/core/lib/Foswiki/Engine/
@@ -108,6 +108,22 @@ sub preparePath {
+sub prepareUploads {
+    my ( $this, $req ) = @_;
+    my %uploads;
+    #SMELL: CLI and CGI appear to support multiple uploads
+    # but Foswiki::UI::Upload only processes a single upload.
+    foreach my $fname ( @{ $req->{param}{filepath} } ) {
+        $uploads{$fname} = new Foswiki::Request::Upload(
+            headers => {},
+            tmpname => $fname
+        );
+    }
+    delete $this->{uploads};
+    $req->uploads( \%uploads );
 sub prepareCookies { }
 sub finalizeHeaders { }

-- GeorgeClark - 25 Nov 2015

Applying it for Foswiki 2.1. Note that if you want to attach a file using utf-8 (non-ASCII) characters, perl needs to be called with the -CA option.
perl -CA ./upload filepath="/path/to/UTF8files/Andröid2.jpg" filename="Andröid2.jpg"  topic=Sandbox.TestTopic
-- GeorgeClark - 25 Nov 2015

Works Perfectly. Thanks!

-- JeanPhilippeRutault - 30 Nov 2015

ItemTemplate edit

Summary bin/upload failed fron the command line
ReportedBy JeanPhilippeRutault
Codebase 2.0.3, trunk
SVN Range
AppliesTo Engine
Priority Enhancement
CurrentState Closed
Checkins distro:b0256a7405a5
TargetRelease minor
ReleasedIn 2.1.0
CheckinsOnBranches master Item13699
masterCheckins distro:b0256a7405a5
ItemBranchCheckins distro:b0256a7405a5
Topic revision: r8 - 03 Feb 2016, 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