Giter VIP home page Giter VIP logo

Comments (13)

emeraldMaster avatar emeraldMaster commented on May 27, 2024

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.

bnlab avatar bnlab commented on May 27, 2024

The problem seems to appear only for main forms, not child forms.

My solution is:

  1. Add to uploader bundle configuration to mapping entry: inject_on_load: false
  2. Add property path to form type for image: 'property_path' => 'imageFile'

Ugly too, but working also.

from vichuploaderbundle.

pixelshaded avatar pixelshaded commented on May 27, 2024

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.

pixelshaded avatar pixelshaded commented on May 27, 2024

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.

dustin10 avatar dustin10 commented on May 27, 2024

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.

stfalcon avatar stfalcon commented on May 27, 2024

:)

from vichuploaderbundle.

topwebstudio avatar topwebstudio commented on May 27, 2024

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,
                ))

#32

from vichuploaderbundle.

TwistedLogic avatar TwistedLogic commented on May 27, 2024

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.

ryall avatar ryall commented on May 27, 2024

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.

stfalcon avatar stfalcon commented on May 27, 2024

@dustin10, pls fixed with issue. I again faced with described problem. many time passed, and the bug is still there

from vichuploaderbundle.

choomz avatar choomz commented on May 27, 2024

@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.

ftassi avatar ftassi commented on May 27, 2024

@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.

stfalcon avatar stfalcon commented on May 27, 2024

@ftassi done! symfony/symfony#5028 (reference)
you can close this issue ;)

from vichuploaderbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.