Comments (13)
I've got the same problem. I solved it by creating custom dataTransformer like this:
namespace Application\Bundle\DefaultBundle\Form\DataTransformer;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\DataTransformerInterface;
/**
* VichUploadableFieldType Tranformer
*/
class VichUploadableFieldTransormer implements DataTransformerInterface
{
/**
* @param null|FIle $name
* @return null
*/
public function transform($name)
{
return null;
}
/**
* @param UploadedFile $data
* @return UploadedFile
*/
public function reverseTransform($data)
{
return $data;
}
}
it looks ugly ) hope it helps
from vichuploaderbundle.
The problem seems to appear only for main forms, not child forms.
My solution is:
- Add to uploader bundle configuration to mapping entry:
inject_on_load: false
- Add property path to form type for image:
'property_path' => 'imageFile'
Ugly too, but working also.
from vichuploaderbundle.
Ive edited my forms by replacing the vich image with something like
->add('image', 'file', array(
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
'property_path' => 'image'
))
from vichuploaderbundle.
I am also getting this error when I leave the image field blank when submitting a form...
Warning: Missing argument 1 for Symfony\Component\HttpFoundation\File\File::__construct(), called in /home/pixelshaded/Projects/Apealz/vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/Type/FormType.php on line 158 and defined in /home/pixelshaded/Projects/Apealz/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/File/File.php line 38
from vichuploaderbundle.
I am not maintaining this bundle any more so maybe one of you guys can find a solution and submit a PR so that @ftassi can review and merge.
from vichuploaderbundle.
:)
from vichuploaderbundle.
An error is being triggered, when using this solution on entity update:
->add('image', 'file', array(
'data_class' => 'Symfony\Component\HttpFoundation\File\File',
'property_path' => 'image',
'required' => false,
))
from vichuploaderbundle.
Let the entity is "User" and the property name is "avatar", my solution in form generation was:
$form = $this->createFormBuilder($current_user)
->add('avatar', 'file', array(
'data_class' => 'Symfony\Component\HttpFoundation\File\File'
))
->getForm();
This way the lifecycle callbacks aren't triggered because no change in filename property and no uploaded file gets moved. Because I think second property is useless, I joined the two property as following:
/**
* @Assert\File(
* maxSize="1M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="user_avatar", fileNameProperty="avatar")
* @ORM\Column(type="string", length=255)
*
* @var File $avatar
*/
protected $avatar;
(fileNameProperty="avatar" is useless, needs refactoring to remove all the logic)
At this point, the upload is working but a wrong url comes out from twig helper. Because we need to get the file name from $avatar instead using $avatar_name, we need a little change to the bundle:
--> Vich\UploaderBundle\Storage\FileSystemStorage#resolvePath line 87;
$mapping->getFileNameProperty()->getValue($obj)->getFilename()
Now everything works. It would be better to remove $filename property and all its logic from the bundle. I will try to fork the bundle to do that, also adding logics for post-upload image processing, and a bundled S3 storage, plus automatic caching policies on filenames for browsers.
Enjoy
from vichuploaderbundle.
Would love to see a fix for this issue. It's affecting the now fully released 2.1.
EDIT: Adding inject_on_load: false
seems to have fixed this for me.
from vichuploaderbundle.
@dustin10, pls fixed with issue. I again faced with described problem. many time passed, and the bug is still there
from vichuploaderbundle.
@stfalcon @ryall A few months ago, I wanted to use this bundle and I found myself facing the same problem. So I decided to develop mine, you can find it at this address.
from vichuploaderbundle.
@stfalcon @webkmua Given the PR to Symfony FileType seems to me that the problem is just the missing data_class option, isn't it ?
If that is true then the users affected by this issue should solve by adding the option in their forms, is that right ? At least until the PR is not accepted and merged in Symfony.
from vichuploaderbundle.
@ftassi done! symfony/symfony#5028 (reference)
you can close this issue ;)
from vichuploaderbundle.
Related Issues (20)
- Deprecation notice in `CacheWarmer::warmUp()` with Symfony 6.4 HOT 1
- download_uri should use publicUrl when using FlysytemStorage HOT 1
- Removing a file from within the message queue handler HOT 7
- Namer is required in configuration from 2.2 to 2.3 HOT 2
- Problem during reading with flysystem HOT 2
- Invalid Schema error while installing the bundle on Symfony 7 HOT 1
- The option "required" does not exist ? HOT 3
- Installation instructions are outdated HOT 2
- Document how to get s3 URL HOT 2
- Issue with VichUploader: unsupported MIME type "image/jpeg" HOT 7
- Install dose not register in bundle.php HOT 1
- Problem with delete when using multiple mappings on one entity
- Using pure Annotation Does not Upload the actual file. @Vich\UploadableField HOT 3
- File injection on load not working reliabely with lazy ghost objects
- How to use metadata with VichUploader HOT 9
- The attribute reader should not trigger an exception for other attributes HOT 3
- Form type lazy load support HOT 3
- publicUrl method check looks for wrong exception.
- Autowire services that implement NamerInterface HOT 3
- Logging of storage operations HOT 7
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 vichuploaderbundle.