Hey,
Please could someone tell(step by step) me, how to enable multiple uploads in vichuploader?
Thank you so much
It's possible?
Yup, it is.
You can find a demo application implementing this in my sandbox.
Hi,
is it possible to do a multiple upload with the multiple option ?
http://symfony.com/doc/current/reference/forms/types/file.html#multiple
Thanks by advance.
@Schneider95 no, it's not.
I have to ask that again to be sure: it is not possible to use a multiple File upload field with this bundle? Even when I have an Entity for each of the multiple uploaded files?
It's possible with many entities
But you said "it's not" to Schneider? So, how can I deal with it, because the setImageFile() (or whatever) gets an Array when a multiple file upload field is used. But it expects a File or EmbeddedFile.
Shouldnt Vich create multiple entities when it gets an array?
I think that we should add working recipe in doc for this case.
Yes, there is an open issue about that (632)
Ok, so just to make it clear (since I am banging my head trying to find a working method):
I have a separate entity Attachment:
/**
* @ORM\Entity
* @Vich\Uploadable
*
*/
class Attachment
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Assert\File(
* maxSize="1M",
* mimeTypes={"application/vnd.ms-excel", "application/pdf", "image/jpeg"}
* )
* @Vich\UploadableField(mapping="attachment_files", fileNameProperty="fileName", size="fileSize")
*
* @var File
*/
private $fileFile;
It's related to another entity called 'Job' (One job can have many attachments):
/**
* @ORM\ManyToOne(targetEntity="Jobs", inversedBy="attachments")
*/
private $job;
public function setJob($job)
{
$this->job = $job;
}
public function getJob()
{
return $this->job;
}
So, if I understand correctly from what @garak mentioned a few times, there is absolutely no way to make the following form field accept multiple files at once (e.g. select a few files with ctrl/cmd held down):
->add('fileFile', VichFileType::class, ['required' => false, 'label' => false, 'attr' => ['class' => 'form-control']])
Is that correct? If yes, can you propose another way of elegantly making this possible with this bundle? (We have another custom implementation, but it's not good).
Thanks.
Question is: entity A has a one-to-many with un uploadable entity B. Since form is tied with entity, the only thing you can currently do is use a collection in A form, and VichFileType in B form.
You can't use a form input type multiple, because there's no entity property to correctly bind with.
Thanks for the quick reply.
So let's say I'd like to use a collection in A form. I am thinking something like this:
$form = $this->createFormBuilder($job)
->add('attachments', CollectionType::class, ['entry_type' => VichFileType::class])
Corresponding entity A properties:
/**
* One Job has Many Attachments
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="job")
*/
private $attachments;
public function getAttachments()
{
return $this->attachments;
}
public function addAttachment(Attachment $attachment)
{
$this->attachments->add($attachment) ;
}
public function removeAttachment(Attachment $attachment)
{
$this->attachments->removeElement($attachment) ;
}
public function __construct() {
$this->attachments = new ArrayCollection();
}
But it gives me an error:
The class "Doctrine\ORM\PersistentCollection" is not uploadable. If you use annotations to configure VichUploaderBundle, you probably just forgot to add
@Vich\Uploadableon top of your entity. If you don't use annotations, check that the configuration files are in the right place. In both cases, clearing the cache can also solve the issue.
Clearing the cache and adding @Vich\Uploadable on top of the Job entity is done, of course.
I suspect this might have something to do with the fact I have not specified the fileFile property in the form.
However, I don't know how to add the fileFile property of the Attachment class. I am thinking using 'entry_options', but I have no idea how.
Or, maybe I am completely on the wrong path :)
Hello,
First of all, thanks for this great Bundle. I use it since Yesterday and it is great for one file upload.
I use Symfony 3.4
But I try to upload more than one file to an Entity.
I have seen, that this is asked already a lot of times, but there was no final answer for this question.
I tried to make a document entity (image) as many2many entity in the class (product). Is there any possibility, or do I have to build it by myself.
Best regards
holema
@plamenh you should try to create a Form for your Attachment entity. Inside that form, add a single field with class VichFileType.
Then, use that form in you CollectionType
@garak thanks for the tip, I believe I solved this a long time ago with some javascript from another thread here. For everyone who is still struggling - you better use a javascript frontend which will upload the files one by one. filepond is a great one, there are many others.
@plamenh Hey, thanks for you tip. I'll solve it with Dropzone, but I liked the way to upload the files so easy to S3. This now have to be done directly with flysystem in a seperate Route.
Most helpful comment
I think that we should add working recipe in doc for this case.