There is no such thing as a predefined object or ORM processing. This has several reasons. This package cannot anticipate project needs in terms of load logic. If someone wants to store files in a database or not, this is completely their own choice and should not be forced by a third-party package. What OneupUploaderBundle provides is a backend for the most common third-party downloaders.
Disclaimer: I copied the copied and extended answer that was already present in the GitHub tracker for this package. There you will find quite a lot of information about how and why this package is what it is now.
Given that you have already installed the Symfony2 working draft, follow the instructions to install this package. I think steps 1 and 2 should not be a problem, so let's go directly to step 3, the configuration.
You said you tried to integrate jQuery File Uploader , so let's create a mapping for it. Open the app/config/config.yml and add the following lines to the end.
oneup_uploader: mappings: gallery: frontend: blueimp
And of course, don't forget to add the following lines to app/config/routing.yml .
oneup_uploader: resource: . type: uploader
So much to configure. For simplicity, we will modify the AcmeDemoBundle.
Open src/Acme/DemoBundle/Resources/views/Welcome/index.html.twig and delete everything between {% block content %} and {% endblock %} . We donβt need it anymore.
Now insert the following:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="https://rawgithub.com/blueimp/jQuery-File-Upload/master/js/vendor/jquery.ui.widget.js"></script> <script type="text/javascript" src="https://rawgithub.com/blueimp/jQuery-File-Upload/master/js/jquery.iframe-transport.js"></script> <script type="text/javascript" src="https://rawgithub.com/blueimp/jQuery-File-Upload/master/js/jquery.fileupload.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#fileupload').fileupload({}); }); </script> <input id="fileupload" type="file" name="files[]" data-url="{{ oneup_uploader_endpoint('gallery') }}" multiple />
Direct your browser to the root directory of this application (app_dev.php). You will see the input field, as expected, and now you can upload some images (for example). Files will be stored in web/uploads/gallery each of them with a unique file name. Please note that we used some CDNs to serve the JavaScript files needed for this.
At this point, you already have a working download form. But besides uploading files to the uploads directory, it does nothing. Here, the next step in the documentation will be helpful.
As I understand your question, you want to create an object that stores the path to the file of the file associated with it in it. To do this, create your Entity class, including all required fields.
<?php namespace Minn\AdsBundle\Entity; use Doctrine\ORM\Mapping as ORM; class MotorsAdsFile { public $id; protected $filename;
Then create an EventListener as described in the documentation for this package.
<?php namespace Acme\HelloBundle\EventListener; use Oneup\UploaderBundle\Event\PostPersistEvent; use Minn\AdsBundle\Entity\MotorsAdsFile; class UploadListener { protected $manager; public function __construct(EntityManager $manager) { $this->manager = $manager; } public function onUpload(PostPersistEvent $event) { $file = $event->getFile(); $object = new MotorsAdsFile(); $object->setFilename($file->getPathName()); $this->manager->persist($object); $this->manager->flush(); } }
And of course, register an event listener.
<services> <service id="acme_hello.upload_listener" class="Acme\HelloBundle\EventListener\UploadListener"> <argument type="service" id="doctrine.orm.entity_manager" /> <tag name="kernel.event_listener" event="oneup_uploader.post_persist" method="onUpload" /> </service> </services>
At this point, the EventListener will be called as soon as the new file is loaded through the configured association. It takes this file, creates a new MotorsAdsFile object and saves the file path to the filename property, saves and deletes it to the base database.
Since I cannot predict your actual logic, this is the simplest example that I can think of. Of course, you can do everything that is necessary in the event listener. (If you need to save this object in another object or the like.)
You will find many other topics in the next steps of the documentation. For example, how would you change the naming strategy for downloaded files or how to enable frequent downloads in case you need to upload large files.