src/PHPDish/Bundle/MediaBundle/Controller/MediaController.php
public function upload(Request $request)
    {
        $uploadedFile = $request->files->get(static::UPLOAD_FIELD_NAME);
        if (is_null($uploadedFile)) {
            throw new \InvalidArgumentException('Bad arguments');
        }

        list($uploader, $urlBuilder) = $this->getUploaderAndBuilder($request);

        $file = $uploader->upload($uploadedFile);
        $response = [
            'key' => $file->getKey(),
            'path' => $urlBuilder->build($file)
        ];
        if ($file instanceof Image) {
            $response['thumb'] = $urlBuilder->buildImageResizeUrl($file, 'middle_square');
        }
        $file->getContent()->close();
        return $this->json($response);
    }
public function upload(Request $request)
    {
        $uploadedFile = $request->files->get(static::UPLOAD_FIELD_NAME);
        if (is_null($uploadedFile)) {
            throw new \InvalidArgumentException('Bad arguments');
        }

        list($uploader, $urlBuilder) = $this->getUploaderAndBuilder($request);

        $file = $uploader->upload($uploadedFile);
        $response = [
            'key' => $file->getKey(),
            'path' => $urlBuilder->build($file)
        ];
        if ($file instanceof Image) {
            $response['thumb'] = $urlBuilder->buildImageResizeUrl($file, 'middle_square');
        }
        $file->getContent()->close();
        return $this->json($response);
    }
附件上传接口.

@Route("/uploads", name="upload")

@param Request $request

@return Response