How can I avoid a '405 Method Not Allowed' when attempting to edit an entity via POST (necessitated by that entity having a file upload)

81 views Asked by At

I am using API Platform and API Platform Admin to add a file upload to an existing entity, using the tutorials here: https://api-platform.com/docs/core/file-upload/ and https://api-platform.com/docs/admin/file-upload/

Having followed the second part of the first tutorial ("Uploading to an Existing Resource with its Fields") I am able to upload files successfully when I create a new instance of my entity. But with this new configuration I am no longer able to edit any instances of my entity (whether or not I upload a file as part of the edit). The API server responds with:

POST http://localhost:8000/api/myentity/37 405 (Method Not Allowed)

This makes sense. The API Platform Admin docs confirm that when the <FileInput> field is present on an <EditGuesser>, it will use POST rather than PUT requests (to work around a PHP bug). But how can I tell API Platform that it should accept POST requests to edit individual entities? I cannot find anything in the tutorials or docs which answers this question.

My entity's current ApiResource annotation looks like this:

#[ApiResource(
    normalizationContext: ['groups' => ['myentity:read']],
    denormalizationContext: ['groups' => ['myentity:write']],
    operations: [
        new GetCollection(),
        new Post(inputFormats: ['multipart' => ['multipart/form-data']]),
        new Get(),
        new Put(),
        new Delete(),
    ],
)]
0

There are 0 answers