Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / files / conduit / FileUploadConduitAPIMethod.php
blob5d0aba6bdd6b90fa1c5bf294f8d98493b8436e83
1 <?php
3 final class FileUploadConduitAPIMethod extends FileConduitAPIMethod {
5 public function getAPIMethodName() {
6 return 'file.upload';
9 public function getMethodDescription() {
10 return pht('Upload a file to the server.');
13 protected function defineParamTypes() {
14 return array(
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 if ($data === null) {
35 throw new Exception(pht('Field "data_base64" must be non-empty.'));
37 $data = $this->decodeBase64($data);
39 $params = array(
40 'authorPHID' => $viewer->getPHID(),
41 'canCDN' => $can_cdn,
42 'isExplicitUpload' => true,
45 if ($name !== null) {
46 $params['name'] = $name;
49 if ($view_policy !== null) {
50 $params['viewPolicy'] = $view_policy;
53 $file = PhabricatorFile::newFromFileData($data, $params);
55 return $file->getPHID();