GRU*_*XKi 0 symfony api-platform.com
我对 API Platform 和 Vich Uploader 的 PUT 请求感到困惑,POST 工作得很好。
这是我的 MediaObject 实体的标头:
/**
* @ORM\Entity
* @ApiResource(
* iri="http://schema.org/MediaObject",
* normalizationContext={
* "groups"={"media_object_read"}
* },
* collectionOperations={
* "post"={
* "controller"=CreateMediaObjectAction::class,
* "deserialize"=false,
* "security"="is_granted('ROLE_USER')",
* "validation_groups"={"Default", "media_object_create"},
* "openapi_context"={
* "requestBody"={
* "content"={
* "multipart/form-data"={
* "schema"={
* "type"="object",
* "properties"={
* "file"={
* "type"="string",
* "format"="binary"
* }
* }
* }
* }
* }
* }
* }
* },
* "get",
* },
* itemOperations={
* "get",
* "put"={"controller"=UpdateMediaObjectAction::class,
* "deserialize"=false,
* "security"="is_granted('ROLE_USER')",
* "validation_groups"={"Default", "media_object_update"},
* "openapi_context"={
* "requestBody"={
* "content"={
* "multipart/form-data"={
* "schema"={
* "type"="object",
* "properties"={
* "file"={
* "type"="string",
* "format"="binary"
* }
* }
* }
* }
* }
* }
* }},
* "delete"={
* "security"="is_granted('ROLE_USER')"
* }
* }
* )
* @Vich\Uploadable
*/
class MediaObject
{...}
Run Code Online (Sandbox Code Playgroud)
在 swagger 中,它会抛出错误,因为文件未附加到请求中。这很奇怪,因为我有完全相同的文件输入字段,只添加了一个 ID 参数。
有人设法做到这一点吗?
自己找到了解决方案!
最后,问题是 PHP 在 PUT 上不能很好地处理 FormData 中的文件,但在 POST 上却不能很好地处理。
因此,如果您遇到同样的问题,请将 itemOperations 的“put”部分中的“method”=“POST”更改为“method”=“POST”。
| 归档时间: |
|
| 查看次数: |
1244 次 |
| 最近记录: |