/** * @param ISyncableFile $syncable * @param int $fileSubType * @param string $fileName * @param bool $forceProxy * @throws KalturaErrors::FILE_DOESNT_EXIST */ protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false) { /* @var $fileSync FileSync */ $syncKey = $syncable->getSyncKey($fileSubType); if (!kFileSyncUtils::fileSync_exists($syncKey)) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); header("Content-Disposition: attachment; filename=\"{$fileName}\""); if ($local) { $filePath = $fileSync->getFullPath(); $wamsAssetId = $fileSync->getWamsAssetId(); if (empty($wamsAssetId)) { $mimeType = kFile::mimeType($filePath); kFile::dumpFile($filePath, $mimeType); } else { kWAMS::getInstance($fileSync->getPartnerId())->dumpFile($wamsAssetId, pathinfo($filePath, PATHINFO_EXTENSION)); } } else { if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) { $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); KalturaLog::info("Redirecting to [{$remoteUrl}]"); if ($forceProxy) { kFile::dumpApiRequest($remoteUrl); } else { //TODO find or build function which redurects the API request with all its parameters without using curl. // or redirect if no proxy header("Location: {$remoteUrl}"); die; } } else { $remoteUrl = $fileSync->getExternalUrl($entryId); header("Location: {$remoteUrl}"); die; } } }
/** * @param ISyncableFile $syncable * @param int $fileSubType * @param string $fileName * @param bool $forceProxy * @throws KalturaErrors::FILE_DOESNT_EXIST */ protected function serveFile(ISyncableFile $syncable, $fileSubType, $fileName, $entryId = null, $forceProxy = false) { /* @var $fileSync FileSync */ $syncKey = $syncable->getSyncKey($fileSubType); if (!kFileSyncUtils::fileSync_exists($syncKey)) { throw new KalturaAPIException(KalturaErrors::FILE_DOESNT_EXIST); } list($fileSync, $local) = kFileSyncUtils::getReadyFileSyncForKey($syncKey, true, false); if ($local) { $filePath = $fileSync->getFullPath(); $mimeType = kFile::mimeType($filePath); return $this->dumpFile($filePath, $mimeType); } else { if (in_array($fileSync->getDc(), kDataCenterMgr::getDcIds())) { $remoteUrl = kDataCenterMgr::getRedirectExternalUrl($fileSync); KalturaLog::info("Redirecting to [{$remoteUrl}]"); if ($forceProxy) { kFileUtils::dumpApiRequest($remoteUrl); } else { //TODO find or build function which redurects the API request with all its parameters without using curl. // or redirect if no proxy header("Location: {$remoteUrl}"); die; } } else { $remoteUrl = $fileSync->getExternalUrl($entryId); header("Location: {$remoteUrl}"); die; } } }