3 abstract class FileConduitAPIMethod
extends ConduitAPIMethod
{
5 final public function getApplication() {
6 return PhabricatorApplication
::getByClass('PhabricatorFilesApplication');
9 protected function loadFileByPHID(PhabricatorUser
$viewer, $file_phid) {
10 $file = id(new PhabricatorFileQuery())
12 ->withPHIDs(array($file_phid))
15 throw new Exception(pht('No such file "%s"!', $file_phid));
21 protected function loadFileChunks(
22 PhabricatorUser
$viewer,
23 PhabricatorFile
$file) {
24 return $this->newChunkQuery($viewer, $file)
28 protected function loadFileChunkForUpload(
29 PhabricatorUser
$viewer,
30 PhabricatorFile
$file,
37 $chunks = $this->newChunkQuery($viewer, $file)
38 ->withByteRange($start, $end)
44 'There are no file data chunks in byte range %d - %d.',
49 if (count($chunks) !== 1) {
53 'There are multiple chunks in byte range %d - %d.',
58 $chunk = head($chunks);
59 if ($chunk->getByteStart() != $start) {
62 'Chunk start byte is %d, not %d.',
63 $chunk->getByteStart(),
67 if ($chunk->getByteEnd() != $end) {
70 'Chunk end byte is %d, not %d.',
75 if ($chunk->getDataFilePHID()) {
77 pht('Chunk has already been uploaded.'));
83 protected function decodeBase64($data) {
84 $data = base64_decode($data, $strict = true);
85 if ($data === false) {
86 throw new Exception(pht('Unable to decode base64 data!'));
91 protected function loadAnyMissingChunk(
92 PhabricatorUser
$viewer,
93 PhabricatorFile
$file) {
95 return $this->newChunkQuery($viewer, $file)
96 ->withIsComplete(false)
101 private function newChunkQuery(
102 PhabricatorUser
$viewer,
103 PhabricatorFile
$file) {
105 $engine = $file->instantiateStorageEngine();
106 if (!$engine->isChunkEngine()) {
109 'File "%s" does not have chunks!',
113 return id(new PhabricatorFileChunkQuery())
115 ->withChunkHandles(array($file->getStorageHandle()));