3 final class PhabricatorFileDropUploadController
4 extends PhabricatorFileController
{
6 public function shouldAllowRestrictedParameter($parameter_name) {
7 // Prevent false positives from file content when it is submitted via
8 // drag-and-drop upload.
13 * @phutil-external-symbol class PhabricatorStartup
15 public function handleRequest(AphrontRequest
$request) {
16 $viewer = $request->getViewer();
18 // NOTE: Throws if valid CSRF token is not present in the request.
19 $request->validateCSRF();
21 $name = $request->getStr('name');
22 $file_phid = $request->getStr('phid');
23 // If there's no explicit view policy, make it very restrictive by default.
24 // This is the correct policy for files dropped onto objects during
25 // creation, comment and edit flows.
26 $view_policy = $request->getStr('viewPolicy');
28 $view_policy = $viewer->getPHID();
31 $is_chunks = $request->getBool('querychunks');
34 'filePHID' => $file_phid,
37 $result = id(new ConduitCall('file.querychunks', $params))
41 return id(new AphrontAjaxResponse())->setContent($result);
44 $is_allocate = $request->getBool('allocate');
48 'contentLength' => $request->getInt('length'),
49 'viewPolicy' => $view_policy,
52 $result = id(new ConduitCall('file.allocate', $params))
56 $file_phid = $result['filePHID'];
58 $file = $this->loadFile($file_phid);
59 $result +
= $file->getDragAndDropDictionary();
62 return id(new AphrontAjaxResponse())->setContent($result);
65 // Read the raw request data. We're either doing a chunk upload or a
66 // vanilla upload, so we need it.
67 $data = PhabricatorStartup
::getRawInput();
69 $is_chunk_upload = $request->getBool('uploadchunk');
70 if ($is_chunk_upload) {
72 'filePHID' => $file_phid,
73 'byteStart' => $request->getInt('byteStart'),
77 $result = id(new ConduitCall('file.uploadchunk', $params))
81 $file = $this->loadFile($file_phid);
82 if ($file->getIsPartial()) {
87 ) +
$file->getDragAndDropDictionary();
90 return id(new AphrontAjaxResponse())->setContent($result);
93 $file = PhabricatorFile
::newFromXHRUpload(
96 'name' => $request->getStr('name'),
97 'authorPHID' => $viewer->getPHID(),
98 'viewPolicy' => $view_policy,
99 'isExplicitUpload' => true,
102 $result = $file->getDragAndDropDictionary();
103 return id(new AphrontAjaxResponse())->setContent($result);
106 private function loadFile($file_phid) {
107 $viewer = $this->getViewer();
109 $file = id(new PhabricatorFileQuery())
111 ->withPHIDs(array($file_phid))
114 throw new Exception(pht('Failed to load file.'));