@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class FileDownloadConduitAPIMethod extends FileConduitAPIMethod {
4
5 public function getAPIMethodName() {
6 return 'file.download';
7 }
8
9 public function getMethodDescription() {
10 return pht('Download a file from the server.');
11 }
12
13 protected function defineParamTypes() {
14 return array(
15 'phid' => 'required phid',
16 );
17 }
18
19 protected function defineReturnType() {
20 return 'nonempty base64-bytes';
21 }
22
23 protected function defineErrorTypes() {
24 return array(
25 'ERR-BAD-PHID' => pht('No such file exists.'),
26 );
27 }
28
29 protected function execute(ConduitAPIRequest $request) {
30 $phid = $request->getValue('phid');
31
32 $file = id(new PhabricatorFileQuery())
33 ->setViewer($request->getUser())
34 ->withPHIDs(array($phid))
35 ->executeOne();
36 if (!$file) {
37 throw new ConduitException('ERR-BAD-PHID');
38 }
39
40 return base64_encode($file->loadFileData());
41 }
42
43}