CC-5741: Create a download action for the File API
This commit is contained in:
parent
16c56e6aff
commit
2b696dbee5
3 changed files with 39 additions and 0 deletions
|
@ -10,5 +10,18 @@ class Rest_Bootstrap extends Zend_Application_Module_Bootstrap
|
|||
$restRoute = new Zend_Rest_Route($front, array(), array(
|
||||
'rest'=> array('media')));
|
||||
assert($router->addRoute('rest', $restRoute));
|
||||
|
||||
$downloadRoute = new Zend_Controller_Router_Route(
|
||||
'rest/media/:id/download',
|
||||
array(
|
||||
'controller' => 'media',
|
||||
'action' => 'download',
|
||||
'module' => 'rest'
|
||||
),
|
||||
array(
|
||||
'id' => '\d+'
|
||||
)
|
||||
);
|
||||
$router->addRoute('download', $downloadRoute);
|
||||
}
|
||||
}
|
|
@ -52,6 +52,32 @@ class Rest_MediaController extends Zend_Rest_Controller
|
|||
*/
|
||||
}
|
||||
|
||||
public function downloadAction()
|
||||
{
|
||||
if (!$this->verifyAuth(true, true))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$id = $this->getId();
|
||||
if (!$id) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file = CcFilesQuery::create()->findPk($id);
|
||||
if ($file) {
|
||||
$con = Propel::getConnection();
|
||||
$storedFile = new Application_Model_StoredFile($file, $con);
|
||||
$baseUrl = Application_Common_OsPath::getBaseDir();
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(200)
|
||||
->appendBody($this->_redirect($storedFile->getRelativeFileUrl($baseUrl).'/download/true'));
|
||||
} else {
|
||||
$this->fileNotFoundResponse();
|
||||
}
|
||||
}
|
||||
|
||||
public function getAction()
|
||||
{
|
||||
if (!$this->verifyAuth(true, true))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue