Closed sta2m closed 2 months ago
Same issue here !
Try to specify input format in operation level instead of specifying in global config.
new Post(
...
controller: FileController::class,
deserialize: false,
inputFormats: ['multipart' => ['multipart/form-data']],
openapi: new Operation(
requestBody: new RequestBody(
content: new ArrayObject([
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => ['file' => ['type' => 'string', 'format' => 'binary']],
],
],
])
)
)
),
My POST config :
new Post(
inputFormats: ['multipart' => ['multipart/form-data']],
processor: UploadOnFile::class,
deserialize: false,
openapi: new Model\Operation(
requestBody: new Model\RequestBody(
content: new \ArrayObject([
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary'
]
]
]
]
])
)
)
),```
try removing multipart in format section in global config(api_platform.yml)
My error is:
Deserialization for the format \"multipart\" is not supported.
I've follow the docs from up to this point and after POST /media_objects
I got an error.
Here I see "new" change which doesn't work.
| Vich doesn't manage the file creation and set the filePath.
It looks like custom processor is needed. Is it true?
@sta2m do you have any progress in this issue?
I had the same issue and I had to solve it with custom provider. Here is my implementation
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
$uploadedFile = $context['request']->files->get('file');
if (!$uploadedFile) {
throw new BadRequestHttpException('"file" is required');
}
$mediaObject = new MediaObject();
$mediaObject->file = $uploadedFile;
return $mediaObject;
}
MediaObject is my entity with Vich Uploadable attribute.
The Post operation mapping is the same, but I have read: false
there as well
We successfully handle file upload in many of our projects, closing as non-issue
In my case the problem was that docs aren't in good order.
After section Resolving the File URL should be a Handling the Multipart Deserialization (!)
API Platform version(s) affected: 3.3.3
Description
I have an issue when doing a POST request to upload a file, using the example from the docs
Error : Could not resolve argument $data of \"api_platform.action.placeholder::__invoke()\", maybe you forgot to register the controller as a service or missed tagging it with the \"controller.service_arguments\"?"
Same as : https://github.com/api-platform/api-platform/issues/2539#issuecomment-2098595585
How to reproduce
See docs
Possible Solution
This workaround work for me : https://github.com/api-platform/api-platform/issues/2539#issuecomment-1790341634
Additional Context
My conf :