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');
34 $data = $this->decodeBase64($data);
37 'authorPHID' => $viewer->getPHID(),
39 'isExplicitUpload' => true,
43 $params['name'] = $name;
46 if ($view_policy !== null) {
47 $params['viewPolicy'] = $view_policy;
50 $file = PhabricatorFile
::newFromFileData($data, $params);
52 return $file->getPHID();