4
* Upload a file to Phabricator.
6
final class ArcanistUploadWorkflow extends ArcanistWorkflow {
11
public function getWorkflowName() {
15
public function getCommandSynopses() {
16
return phutil_console_format(<<<EOTEXT
17
**upload** __file__ [__file__ ...] [--json]
22
public function getCommandHelp() {
23
return phutil_console_format(<<<EOTEXT
25
Upload a file from local disk.
30
public function getArguments() {
33
'help' => 'Output upload information in JSON format.',
39
protected function didParseArguments() {
40
if (!$this->getArgument('paths')) {
41
throw new ArcanistUsageException('Specify one or more files to upload.');
44
$this->paths = $this->getArgument('paths');
45
$this->json = $this->getArgument('json');
48
public function requiresAuthentication() {
52
private function getPaths() {
56
private function getJSON() {
60
public function run() {
61
$conduit = $this->getConduit();
65
foreach ($this->paths as $path) {
66
$name = basename($path);
67
$this->writeStatusMessage("Uploading '{$name}'...\n");
69
$data = Filesystem::readFile($path);
70
} catch (FilesystemException $ex) {
71
$this->writeStatusMessage(
72
"Unable to upload file: ".$ex->getMessage()."\n");
73
$results[$path] = null;
77
$phid = $conduit->callMethodSynchronous(
80
'data_base64' => base64_encode($data),
83
$info = $conduit->callMethodSynchronous(
89
$results[$path] = $info;
91
if (!$this->getJSON()) {
93
echo " F{$id} {$name}: ".$info['uri']."\n\n";
97
if ($this->getJSON()) {
98
echo json_encode($results)."\n";
100
$this->writeStatusMessage("Done.\n");