I'm using Symfony 3.1 trying to attach multiple files to a form.
So far I can upload files, create an entity and store in database for each one. Using OneupUploaderBundle with FineUploader.
The problem is those file are not attached with the rest of my form data.
<?php
namespace AppBundle\EventListener;
use Doctrine\ORM\EntityManager;
use Oneup\UploaderBundle\Event\PostPersistEvent;
use AppBundle\Entity\AppointmentFile;
class AppointmentUploadListener
{
protected $manager;
public function __construct(EntityManager $manager)
{
$this->manager = $manager;
}
public function onUpload(PostPersistEvent $event)
{
dump($event);
die();
$file = $event->getFile();
$object = new AppointmentFile();
$object->setFilename($file->getPathName());
$this->manager->persist($object);
$this->manager->flush();
}
}
I tried adding my form serialized to the upload parameters, but if I've 3 files, it would upload my form data 3 times.
var uploader = new qq.FineUploader({
element: document.getElementById('fine-uploader'),
debug: true,
form: 'newAppointmentForm',
request: {
endpoint: "{{ oneup_uploader_endpoint('appointment') }}",
params: {
appointment: $('#newAppointmentForm').serialize()
},
}
});
The main purpose is to store an Appointment with attached files. The entities are therefore Appointment (columns: appointment data and arraycollection of files) and AppointmentFile (columns: id, filename, and mime/type).
Any advise is welcome.