Comments (11)
All step data is serialized into the session. But unfortunately, just serializing file uploads is not possible. You'll have to implement file upload handling yourself and immediately move the uploaded file somewhere. I haven't done that myself using a flow yet.
from craueformflowbundle.
@madarco: Did you find a way to achieve what you wanted?
from craueformflowbundle.
Only with a workaround: I check if there is a file to upload and set the value in the session.
Then, before $flow->bind($values); I do:
$values->setUploadedPhoto($this->getRequest()->getSession()->get('tmpUploadedFile'));
And when I do $flow->reset(), I also do:
$this->getRequest()->getSession()->remove('tmpUploadedFile');
from craueformflowbundle.
So, if there's an uploaded file, you move it and save its path in the session? Do you also handle the case that a file is uploaded but the flow isn't finished (e.g. if the user just leaves the page)?
from craueformflowbundle.
No, in that case the file and the session variable will remain there.
I use MongoDB GridFS to store files, so I'll run a job that check for spurious files and remove them...
Not the best solution :)
from craueformflowbundle.
Alright, but it seems to get the job done. ;)
from craueformflowbundle.
@craue @madarco So, what's the status on this ? I'm facing the same problem with NULL values on the file field.
Can I use your temp solution madarco ?
from craueformflowbundle.
yes @tristanbes
It is actually working for me on production
from craueformflowbundle.
Hi, @madarco, I'm a beginner for symfony2, and I also faced the same problem with you. However, I can't figure out how to walkaround with your method. Would you please do me a favor to post detailed code? It would be highly appreciated.
from craueformflowbundle.
Sure @oopsFrogs, sorry for the late reply.
My fix is that:
- on every step of the flow check if the file field is in the request
- if it is in the request method (ie: was submitted in the html form), save the file in a temp directory, and save in the session the actual path to the file.
- in the last step, get the value from the session and save the value in your Document or Entity.
This is the code:
What I do is to call a method after the check for $flow->isValid($form) in your action, so that it is executed on every step of the flow:
if ($flow->isValid($form)) {
//XXX: fix for unknown bug in FormFlow, we'll handle the photo field manually (not in the Flow class):
$photo = $this->_fixUploadFile($values->getUploadedPhoto());
if($photo) {
$values->setUploadedPhoto($photo);
}
//ENDIFX
if ($flow->nextStep()) {
...
//omissis: check if nextStep()...
}
//All steps completed:
$dm->persist($values);
//Important!!! clear the variable from the session when you have done:
$this->getRequest()->getSession()->remove('tmpUploadedFile');
$dm->flush();
return $this->redirect(completeUrl);
}
//XXX: exec the fix also here, so that in case of validation errors, the user can see the file uploaded in the form:
$photo = $this->_fixUploadFile($values->getUploadedPhoto());
if($photo) {
$values->setUploadedPhoto($photo);
}
//ENDIFX
return array('form' => $form->createView(), 'flow' => $flow, 'values' => $values);
The method _fixUploadFile simply save the file and store in the session the actual file path, to be used in the last step of the flow (when you save it in the db).
This is my method, I upload the file to mongoDb, but the same applies if you save the file on disk too:
public function _fixUploadFile($file) {
if(!empty($file) && $file instanceof UploadedFile) {
$picture = new Picture();
$picture->setFile($file->getPathname());
$picture->setExtension($file->guessExtension());
$picture->setMimetype($file->getMimeType());
$picture->setType('profile-upload');
$picture->setSizeType('original');
$imagine = new Imagine();
$size = $imagine->open($file->getPathname())->getSize();
$picture->setWidth($size->getWidth());
$picture->setHeight($size->getHeight());
$picture->setOriginalName($file->getClientOriginalName());
$this->get('doctrine.odm.mongodb.document_manager')->persist($picture);
$this->get('doctrine.odm.mongodb.document_manager')->flush();
$this->getRequest()->getSession()->set('tmpUploadedFile', "" . $picture->getId());
}
return $this->getRequest()->getSession()->get('tmpUploadedFile');
}
from craueformflowbundle.
Thank you, @madarco
from craueformflowbundle.
Related Issues (20)
- How to navigate freely through the steps ? HOT 2
- Step list structure HOT 9
- Lost data for a 3-steps flow when pressing back button twice then next button HOT 4
- Handle file uploads with Amazon Web service S3 HOT 2
- Where are stored "not mapped" properties ? HOT 5
- Bug - Fields not mapped are lost accross steps
- there is no way to hidden the back button (as we had on start over button)
- Event fired Twice (part 2)
- There is any way to add custom new button on last step HOT 2
- Step rendering with Hotwired/Turbo HOT 2
- Don't use this bundle anymore : HOT 3
- Bug - Array field's Data on CollectionType not saved
- Is it still maintained? HOT 1
- Add $stepForm in PreviousStepInvalidEvent
- Call to a member function drop() on null?
- Is there a way to nested form flow? HOT 2
- When redirect after submit is enabled, back and reset buttons don't update URL parameters? HOT 1
- I have 2 forms in a step and i want to display one depending on choice option. How to do that?
- Deprecation Message
- Support Symfony 7 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from craueformflowbundle.