docs icon indicating copy to clipboard operation
docs copied to clipboard

Handling File Upload docs unclear

Open erikkubica opened this issue 6 years ago • 1 comments

Hello,

Today I came across the https://api-platform.com/docs/core/file-upload/ and I have a few questions I was hoping to get answered there.

There is lot of magic happening in the background, like how/when is the MediaObject persisted, it´s sent to the CreateMediaObjectAction where it´s returned and as far I have understood it´s "hooked" with the ResolveMediaObjectContentUrlSubscriber where if it´s not a general response and the resource class is MediaObject then the contentUrl get´s resolved. How does api plafrom know that a post request to /media_objects/ needs to go to the CreateMediaObjectAction.

But after that, where is it persisted with the new value, is everything recursively in controllerResult with pointers so it does not need return value? How does Symfony/API-Platform knows that this entity needs to be persisted if it uses custom action.

It´s generally good practice to optimize images and or resize/crop them (don´t even remember a project where I did not do that). I saw few questions over the internet with answers pointing to some bundles that can do that, in which case developers handle the file upload manually in custom controller without using file upload bundle that the docs suggests. From the docs I have no idea how can this be achieved.

Having to first upload the image, than save the entity person is uploading to is not always a very nice solution, and there should be some option to submit the file and other data to the API in one single form submit.

What if I want to call MediaObject differently, or add request params to it, or change the route to it....

Thanks

erikkubica avatar Nov 12 '19 13:11 erikkubica

Indeed. It would be nice to see the example book api have this feature integrated, so we can see how it is actually done.

ghost avatar Nov 23 '19 03:11 ghost