@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 57 lines 1.4 kB view raw
1<?php 2 3final class FileUploadConduitAPIMethod extends FileConduitAPIMethod { 4 5 public function getAPIMethodName() { 6 return 'file.upload'; 7 } 8 9 public function getMethodDescription() { 10 return pht('Upload a file to the server.'); 11 } 12 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', 19 ); 20 } 21 22 protected function defineReturnType() { 23 return 'nonempty guid'; 24 } 25 26 protected function execute(ConduitAPIRequest $request) { 27 $viewer = $request->getUser(); 28 29 $name = $request->getValue('name'); 30 $can_cdn = (bool)$request->getValue('canCDN'); 31 $view_policy = $request->getValue('viewPolicy'); 32 33 $data = $request->getValue('data_base64'); 34 if (!phutil_nonempty_string($data)) { 35 throw new Exception(pht('Field "data_base64" must be non-empty.')); 36 } 37 $data = $this->decodeBase64($data); 38 $params = array( 39 'authorPHID' => $viewer->getPHID(), 40 'canCDN' => $can_cdn, 41 'isExplicitUpload' => true, 42 ); 43 44 if ($name !== null) { 45 $params['name'] = $name; 46 } 47 48 if ($view_policy !== null) { 49 $params['viewPolicy'] = $view_policy; 50 } 51 52 $file = PhabricatorFile::newFromFileData($data, $params); 53 54 return $file->getPHID(); 55 } 56 57}