Item13867: bin/upload failed fron the command line
Priority: Enhancement
Current State: Closed
Released In: 2.1.0
Target Release: minor
Applies To: Engine
Component:
Branches: master
Item13699
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
http://foswiki.org/Extensions/UpdateAttachmentsPlugin.
--
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/CLI.pm
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/CLI.pm b/core/lib/Foswiki/Engine/CLI.pm
index 9653c38..eb702cd 100644
--- a/core/lib/Foswiki/Engine/CLI.pm
+++ b/core/lib/Foswiki/Engine/CLI.pm
@@ -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