-
-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Live Component] Are file uploads supported? #486
Comments
Hey, I tried many things to send file with Live Components. The only way I found is to force norender on my form and to send manually my file with stimulusJS.
I personnaly wait |
Hey @benr77, Not officially supported yet. We want to support this in a way that allows using a filesystem abstractions (Flysystem). I've been hacking on a sort of symfony-flysystem bridge to help with this. Long story, short, it's definitely on our radar! |
OK, great thanks for the update. I'll just implement my file upload outside of a Live Component for the time being. This will be a great feature - I'm finding Live Components are so powerful for decoupling my front end I'm trying to use them at every opportunity. |
Hey, I am experiencing the same issue. Any news on this topic ? |
Hey @kbond Do you know when will this feature be supported ? |
Hey! This is still on my radar but I've been busy with other things lately. Rest assured it hasn't been forgotten but I don't have an ETA at this time. |
Thanks for your reply and good luck for this feature ! |
Hi! Any news about this issue ? |
#834 is the latest iteration I think we'll be going with. |
Hello, I commented in #834 but it's a pull requst and not an issue. |
I think that's a wrong assumption in docs, because only v2.11 released file upload |
Thanks for all the hard work getting this feature up and running! I see there is an example on the UX site showing how to do file uploads inside Live Components, but it does not use Symfony Forms. I have almost got it working using the Form component, but the file field in the form data class is always null. I have a hack to add it from the Request object directly: $this->submitForm();
/** @var MyFormData $formData */
$formData = $this->getForm()->getData();
// Hack to put the actual UploadedFile object on to the form data class
$formData->mapFile = $request->files->all('form_name')['pdfFile']; This seems to work OK, but I think it means that any validation constraints on the Does all this sound about right based on the current state of support for file uploads inside Live Components? Thanks! |
I agree, something is missing to properly manage uploads using the Symfony form. In my case, I use VichUploader on a Media entity to store all my files. I have an entity that has a Media collection, and I use LiveCollectionType to render this media collection. I submit the form via the component {{ form_start(form, {attr: {
'data-action': 'live#action',
'data-action-name': 'prevent|files|save',
}}) }} In the component, I'm doing something like this to handle files and place them in correct collection position : #[LiveAction]
public function save(EntityManagerInterface $entityManager, Request $request): void
{
$files = $request->files->all();
if (\array_key_exists('meeting_point', $files)) {
foreach ($files['meeting_point']['medias'] as $key => $file) {
$uploadedFile = $file['file']['file'];
$this->formValues['medias'][$key]['file']['file'] = $uploadedFile;
}
}
$this->submitForm();
/** @var MeetingPoint $meetingPoint */
$meetingPoint = $this->getForm()->getData();
$entityManager->persist($meetingPoint);
$entityManager->flush();
} It seems to work. I wonder if we could set up something generic to automatically correctly map the submitted files with the entities to which they should belong, and therefore obtain the same operation as for a symfony form submitted and managed from the controller |
Hello, I want to provide a bit of an update on this issue/feature - it is still very much on my radar. What we need are some pieces in place before we can add this feature in a robust way. Let me explain:
|
Thank you for this suggestion. |
This feature is still needed and I believe @kbond is across things - maybe he can detail if anything has changed since his last post. |
Its very much on our radar, but you should not expect any concrete thing until, well, the (future) day there is :) Still an open source project made by contributors on their free time so the best way to see something release is often to contribute :) |
Hello again. I'm trying to do a file upload in a Live Component. I've tried with both
DropzoneType
and the regularFileType
but running into the same problem I think.I have been reading related issues #354, #289, #299 etc but I'm unsure of the current state of play. I believe these discussions are only related to using a UX component such as Dropzone inside the Live Component.
Even with a standard
FileType
field in the form, as soon as I add a file to be uploaded to the form field, the component reloads and I think the file to be uploaded is lost, so when I then submit the form it sends empty data for the file field.I can live without Dropzone support in the Live Component for the moment, but of course that would be great to have - but should the standard FileType field work?
How can I stop the Live Component re-rendering and losing the selected file as soon as I add the file to the field?
Thank you.
The text was updated successfully, but these errors were encountered: