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(
|
$restRoute = new Zend_Rest_Route($front, array(), array(
|
||||||
'rest'=> array('media')));
|
'rest'=> array('media')));
|
||||||
assert($router->addRoute('rest', $restRoute));
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -51,6 +51,32 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
->appendBody(json_encode(CcFilesQuery::create()->find()->toArray(BasePeer::TYPE_FIELDNAME)));
|
->appendBody(json_encode(CcFilesQuery::create()->find()->toArray(BasePeer::TYPE_FIELDNAME)));
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()
|
public function getAction()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue