3 final class FileUploadChunkConduitAPIMethod
4 extends FileConduitAPIMethod
{
6 public function getAPIMethodName() {
7 return 'file.uploadchunk';
10 public function getMethodDescription() {
11 return pht('Upload a chunk of file data to the server.');
14 protected function defineParamTypes() {
19 'dataEncoding' => 'string',
23 protected function defineReturnType() {
27 protected function execute(ConduitAPIRequest
$request) {
28 $viewer = $request->getUser();
30 $file_phid = $request->getValue('filePHID');
31 $file = $this->loadFileByPHID($viewer, $file_phid);
33 $start = $request->getValue('byteStart');
35 $data = $request->getValue('data');
36 $encoding = $request->getValue('dataEncoding');
39 $data = $this->decodeBase64($data);
44 throw new Exception(pht('Unsupported data encoding.'));
46 $length = strlen($data);
48 $chunk = $this->loadFileChunkForUpload(
54 // If this is the initial chunk, leave the MIME type unset so we detect
55 // it and can update the parent file. If this is any other chunk, it has
56 // no meaningful MIME type. Provide a default type so we can avoid writing
57 // it to disk to perform MIME type detection.
61 $mime_type = 'application/octet-stream';
65 'name' => $file->getMonogram().'.chunk-'.$chunk->getID(),
66 'viewPolicy' => PhabricatorPolicies
::POLICY_NOONE
,
70 if ($mime_type !== null) {
71 $params['mime-type'] = 'application/octet-stream';
74 // NOTE: These files have a view policy which prevents normal access. They
75 // are only accessed through the storage engine.
76 $chunk_data = PhabricatorFile
::newFromFileData(
80 $chunk->setDataFilePHID($chunk_data->getPHID())->save();
82 $needs_update = false;
84 $missing = $this->loadAnyMissingChunk($viewer, $file);
86 $file->setIsPartial(0);
91 $file->setMimeType($chunk_data->getMimeType());