Description
The document in question: http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html
There are a number of open issues about this document:
- File upload handling with doctrine #2278
- Cookbook entry for advanced file upload implementation #1559
- File Upload: Correctly instruct how to handle updates #600
- Fix the "doctrine file uploads" cookbook examples, see symfony/symfony-d... #2120
Here's a summary of issues:
a) I really dislike the use of paths inside the entity itself
b) Complication of the callbacks not triggering if only the file object property is changed (since it's not mapped). This may not be avoidable, but should be solved as simply as possible).
c) I agree that the VichUploaderBundle should be suggested to help with much of this
Suggestions: One big theme is building-up in complexity from little to more.
-
We should first show how to upload files. It's very easy and includes implementing the UploadedFile object which you can get off of the Request. This should live as a little "cookbook" in the HttpFoundation component
-
Have a cookbook article that talks about uploading in Symfony, but nothing about Doctrine. This would include using a Form, validation, and moving the uploaded file in the controller.
-
Update the Doctrine file uploads doc to build off of the new, short doc in (2). So, it would start with pointing you to (2), then continue by building an entity, persisting, etc.
Questions
- What is a good (but still somewhat simple - I don't want to introduce services with lots of big logic to do this) way to keep track of where different "types" of files are uploaded. For example, suppose a site allows you to upload avatars and product images - the first is stored in
/uploads/avatars
and the second in/uploads/products
. Where each type is stored should be stored in configuration somewhere, then accessed in the controller and in the view. I want to show a nice, but still simple way you might handle this.