Jaimy
Jaimy

Reputation: 517

Display files uploaded to AWS S3 using Dropzone and Symfony

I have a Dropzone form to upload files to AWS S3 in Symfony. The action the form calls looks like this.

/**
     * @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();
    }

Now I want to display the already existing files in the Dropzone form. So when someone wants to upload some files, the form shows thumbnails of files that have already been uploaded. The problem is that I have no idea how to do this and I can't find any information on this particular 'construction' anywhere.

Upvotes: 1

Views: 593

Answers (1)

d23
d23

Reputation: 186

you should return a JsonResponse with the file url, probably $file_link

In the ajax call that is doing the upload on success you parse the response to get the file_link and show thumbnail with it.

Upvotes: 2

Related Questions