小编let*_*lim的帖子

Symfony - API 平台 - 文件上传

我正在尝试按照文档使用API PLatform实现文件上传使用 Vich使用。但它不起作用,准确地说,MediaObject 没有被我根据我的请求发送的文件水合。

我完全遵循 API Platform 提供的说明书,但我的表单似乎没有很好地处理请求,因为它没有通过约束验证,我从 API 得到了这个答案:

{
    "type": "https:\/\/tools.ietf.org\/html\/rfc2616#section-10",
    "title": "An error occurred",
    "detail": "file: This value should not be null.",
    "violations": [
        {
        "propertyPath": "file",
        "message": "This value should not be null."
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的要求是基本的:标头是 multipart/form-data,我发送一个小文件 (78Ko):"file" => image.jpg

当我转储 $request 对象时,文件在其中,但 $form->getData() 没有被水合。知道为什么吗?

这是我的 MediaObject :

namespace App\Entity;

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Traits\updatedAt;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Entity\File;
use Vich\UploaderBundle\Mapping\Annotation …
Run Code Online (Sandbox Code Playgroud)

file-upload symfony vichuploaderbundle api-platform.com

8
推荐指数
1
解决办法
4644
查看次数