我正在使用symfony2构建API,问题是我想要检索上传到某个目录的文件,每当我在浏览器中键入de url时,我都会收到以下消息:
{"status":{"code":0,"msg":"No route found for \"GET \/asdf.txt\""}}
有人知道为什么会这样吗?似乎apache无法提供此目录中的静态文件。文件实际上在那里,但无法通过网址提供。
我正在使用此控制器上传文件:
public function postAttachmentAction($id, Request $request)
{
$file = $request->files->get("attachment");
$em = $this->getDoctrine()->getManager();
$exam = $em->find("MyBundle\ApiBundle\Entity\TheEntity", $id);
if (!$exam) throw new Exception("No stuff was found with given id", 404);
foreach ($request->files as $uploadedFile) {
$fileName = md5($uploadedFile->getClientOriginalName() . microtime()) . "." . $uploadedFile->guessExtension();
$file->move("uploads", $fileName);
$exam->setAttachmentPath("/uploads/". $fileName);
}
return $this->getResponse(200, "/uploads/". $fileName);
}