我正在使用 Zend Framework 2 和 AngularJS 构建一个网站。我有一个在 ZF2 中运行的 Restful Web 服务,我在客户端上使用 AngularJS 来访问该 Web 服务。
现在我想向我的网站添加相册,围绕此主题我有以下问题:
- 如何将图像提供给 AngularJS?我应该返回一个包含服务器上目录链接的 json 吗?然后使用
<img src="" />
加载它,或者还有其他更好的方法吗?
最佳答案
您还可以通过修改响应然后从操作中返回图像来发回图像,如下所示
$data = //Get the file information
$response = $this->getEvent()->getResponse();
$response->setStatusCode(Response::STATUS_CODE_200);
$response->getHeaders()->addHeaderLine('Content-Type: ' . $data['file_mime'])
->addHeaderLine('Content-Length: ' . $data['file_size'])
->addHeaderLine('Content-Disposition: attachment; filename="' . $data['file_name'] . '"');
$response->setContent($data['file_data']); // or stream file data
return $response;
关于javascript - ZF2 : Restful and image combination,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29013891/