Skip to content

Refactor the Uploading Document #2346

Closed
@weaverryan

Description

@weaverryan

The document in question: http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html

There are a number of open issues about this document:

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.

  1. 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

  2. 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.

  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions