/** * Media File Upload * Upload a media file in parts * @return <XiboAPIResponse> */ public function LibraryMediaFileUpload() { // Does this user have permission to call this webservice method? if (!$this->user->PageAuth('content')) { return $this->Error(1, 'Access Denied'); } Kit::ClassLoader('file'); $file = new File(); $fileId = $this->GetParam('fileId', _INT); $checkSum = $this->GetParam('checksum', _STRING); $payload = $this->GetParam('payload', _STRING); $payloadMd5 = md5($payload); // Checksum the payload if ($payloadMd5 != $checkSum) { // Debug::LogEntry('audit', 'Sent Checksum: ' . $checkSum, 'RestXml', 'LibraryMediaFileUpload'); // Debug::LogEntry('audit', 'Calculated Checksum: ' . $payloadMd5, 'RestXml', 'LibraryMediaFileUpload'); // Debug::LogEntry('audit', 'Payload: ' . $payload, 'RestXml', 'LibraryMediaFileUpload'); return $this->Error(2); } // Payload will be encoded in base64. Need to decode before handing to File class $payload = base64_decode($payload); if ($fileId == 0) { // New upload. All users have permissions to upload files if they have gotten this far if (!($fileId = $file->NewFile($payload, $this->user->userid))) { return $this->Error($file->GetErrorNumber()); } } else { // Check permissions if (!$this->user->FileAuth($fileId)) { return $this->Error(1, 'Access Denied'); } // Continue upload if (!$file->Append($fileId, $payload)) { return $this->Error($file->GetErrorNumber()); } } // Current offset $size = $file->Size($fileId); // Return the fileId return $this->Respond($this->ReturnAttributes('file', array('id' => $fileId, 'offset' => $size))); }
public function getSize() { $size = File::Size($this->findStream()); if ($size < 1024 * 1024 * 1024) { return sprintf("%.1f MB", $size / 1024.0 / 1024.0); } else { return sprintf("%.1f GB", $size / 1024.0 / 1024.0 / 1024.0); } }