Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/conduit/FileDownloadConduitAPIMethod.php
12241 views
1
<?php
2
3
final 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
}
44
45