3 final class FileUploadConduitAPIMethod
extends FileConduitAPIMethod
{
5 public function getAPIMethodName() {
9 public function getMethodDescription() {
10 return pht('Upload a file to the server.');
13 protected function defineParamTypes() {
15 'data_base64' => 'required nonempty base64-bytes',
16 'name' => 'optional string',
17 'viewPolicy' => 'optional valid policy string or <phid>',
18 'canCDN' => 'optional bool',
22 protected function defineReturnType() {
23 return 'nonempty guid';
26 protected function execute(ConduitAPIRequest
$request) {
27 $viewer = $request->getUser();
29 $name = $request->getValue('name');
30 $can_cdn = (bool)$request->getValue('canCDN');
31 $view_policy = $request->getValue('viewPolicy');
33 $data = $request->getValue('data_base64');
35 throw new Exception(pht('Field "data_base64" must be non-empty.'));
37 $data = $this->decodeBase64($data);
40 'authorPHID' => $viewer->getPHID(),
42 'isExplicitUpload' => true,
46 $params['name'] = $name;
49 if ($view_policy !== null) {
50 $params['viewPolicy'] = $view_policy;
53 $file = PhabricatorFile
::newFromFileData($data, $params);
55 return $file->getPHID();