使用 Dropzone 和 Symfony 显示上传到 AWS S3 的文件
Display files uploaded to AWS S3 using Dropzone and Symfony
我有一个 Dropzone 表单可以将文件上传到 Symfony 中的 AWS S3。表单调用的操作如下所示。
/**
* @Route("/upload/{inspection}")
* @ParamConverter("inspection", class="AppBundle:Inspection")
*/
public function uploadAction(Request $request, $inspection)
{
$file = $request->files->get('file');
$fileEntity = new File();
$fileEntity->setFileLink($file);
$fileEntity->setInspection($inspection);
$file_link = $this->get('app.entity.inspectionFiles')->handleUpload($fileEntity);
$fileEntity->setFile($file_link);
$inspection->addFile($fileEntity);
$em = $this->getDoctrine()->getManager();
$em->persist($fileEntity);
$em->flush();
return new Response();
}
现在我想在 Dropzone 表单中显示已经存在的文件。因此,当有人要上传一些文件时,该表单会显示已上传文件的缩略图。问题是我不知道该怎么做,而且我在任何地方都找不到关于这个特定 'construction' 的任何信息。
你应该 return 一个带有文件 url 的 JsonResponse,可能是 $file_link
在成功上传的 ajax 调用中,您解析响应以获取 file_link 并显示缩略图。
我有一个 Dropzone 表单可以将文件上传到 Symfony 中的 AWS S3。表单调用的操作如下所示。
/**
* @Route("/upload/{inspection}")
* @ParamConverter("inspection", class="AppBundle:Inspection")
*/
public function uploadAction(Request $request, $inspection)
{
$file = $request->files->get('file');
$fileEntity = new File();
$fileEntity->setFileLink($file);
$fileEntity->setInspection($inspection);
$file_link = $this->get('app.entity.inspectionFiles')->handleUpload($fileEntity);
$fileEntity->setFile($file_link);
$inspection->addFile($fileEntity);
$em = $this->getDoctrine()->getManager();
$em->persist($fileEntity);
$em->flush();
return new Response();
}
现在我想在 Dropzone 表单中显示已经存在的文件。因此,当有人要上传一些文件时,该表单会显示已上传文件的缩略图。问题是我不知道该怎么做,而且我在任何地方都找不到关于这个特定 'construction' 的任何信息。
你应该 return 一个带有文件 url 的 JsonResponse,可能是 $file_link
在成功上传的 ajax 调用中,您解析响应以获取 file_link 并显示缩略图。