Skip to content

Patched documentation problem with VichUploaderBundle#2156

Closed
D3xime wants to merge 1 commit into
api-platform:4.1from
D3xime:patch-documentation
Closed

Patched documentation problem with VichUploaderBundle#2156
D3xime wants to merge 1 commit into
api-platform:4.1from
D3xime:patch-documentation

Conversation

@D3xime
Copy link
Copy Markdown

@D3xime D3xime commented Apr 14, 2025

This PR is aimed to patch documentation problem in case with VichUploaderBundle

See issue for context : #2058

fix: patch indentation for mutiples markdown Files. Change documentation for file upload to indicate well the way to use ApiPlatform with VIchUploaderBundle

…ion for file upload to indicate well the way to use ApiPlatform with VIchUploaderBundle
Comment thread symfony/file-upload.md
new GetCollection(),
new Post(
inputFormats: ['multipart' => ['multipart/form-data']],
controller: CreateMediaObjectAction::class,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not want to recommend using a controller

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What can we do to create a media with API platform then ? Nobody told me how to do it without using a controller. Is there a way to do this ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using a processor like I documented doesn't work?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where the documentation for file upload use a processor. Could you provide me an example ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I added that documentation but I must have dreamed it haha.

Anyways it's quite straightforward:

final class CreateMediaObjectProcessor implements ProcessorInterface
{
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
    {
        $uploadedFile = $context['request']->files->get('file');
        if (!$uploadedFile) {
            throw new BadRequestHttpException('"file" is required');
        }
        $mediaObject = new MediaObject();
        $mediaObject->file = $uploadedFile;
        return $mediaObject;
    }
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. I will update the PR when I have time to do this. Thanks for the example.

@vinceAmstoutz
Copy link
Copy Markdown
Member

@D3xime Do you plan to keep going?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants