Skip to content

Commit

Permalink
Item13867: Enable upload from CLI script
Browse files Browse the repository at this point in the history
The CLI engine has to prepare the upload parameters.
  • Loading branch information
gac410 committed Nov 25, 2015
1 parent 6be968a commit b0256a7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/data/System/CommandAndCGIScripts.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1443040360" format="1.1" version="1"}%
%META:TOPICINFO{author="ProjectContributor" date="1448477054" format="1.1" version="1"}%
%META:TOPICPARENT{name="DeveloperDocumentationCategory"}%
%STARTINCLUDE%
---+ CGI and Command Line Scripts
Expand Down Expand Up @@ -592,6 +592,9 @@ Uploads an attachment to a topic. The HTTP request is expected to be in =multipa
*Tips*
* You can use a tool like =curl= to upload files from the command line using this script.
* You can call upload easily from !XmlHttpRequest in Javascript.
* You can directly invoke upload from the CLI script.__New with Foswiki 2.1__
* You must use the Perl CLI options '-CA' if the filename contains non-ASCII characters.
* ex. Run from the bin directory: =perl -CA ./upload filepath="/path/and/filename.dat" filename="attachname.dat" topic=Sandbox.ExistingTopic=

<div class="foswikiHelp">
*%X% Note:* The =upload= script can only be called via HTTP POST method. Make sure you specify =method="post"= if you call the =upload= script via a form action. It is not possible to call =upload= from an =&lt;a href ...&gt;= link.
Expand Down
16 changes: 16 additions & 0 deletions core/lib/Foswiki/Engine/CLI.pm
Expand Up @@ -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 { }
Expand Down

0 comments on commit b0256a7

Please sign in to comment.