Giter VIP home page Giter VIP logo

Comments (7)

PeterFour avatar PeterFour commented on May 24, 2024 1

I'm reopening the issue because I have the same problem and I wonder it this is intended behaviour or if that's fixed ?

The first name field is properly assigned, however the second one (or third one for that matter) will stay null causing SQL to fail.

Do we have to use separate nameer everytime we have more than one field ?

PS : This is failing when using DataFixtures

from vichuploaderbundle.

ftassi avatar ftassi commented on May 24, 2024

Just add annotated property to the entity, you can have as many files as you want in your entity

from vichuploaderbundle.

Raulken avatar Raulken commented on May 24, 2024

ok but i have to add also in config the service?

i have to upload 2 images

/**
* @Assert\File(
* maxSize="1M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @vich\UploadableField(mapping="articolo_image", fileNameProperty="imageName")
*
* @var File $image
*/
public $image;

/**
 * @ORM\Column(type="string", length=255, name="image_name")
 *
 * @var string $imageName
 */
public $imageName;

/**
 * @Assert\File(
 *     maxSize="1M",
 *     mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
 * )
 * @Vich\UploadableField(mapping="articolo_image", fileNameProperty="imageName2")
 *
 * @var File $image2
 */
public $image2;

/**
 * @ORM\Column(type="string", length=255, name="image_name2")
 *
 * @var string $imageName2
 */
public $imageName2;

the first image upload
the second....
The file "/tmp/phpGr68Lx" does not exist
?

from vichuploaderbundle.

cipherchien avatar cipherchien commented on May 24, 2024

I got the same problem, after 4 hours hard time, I got the answer.

the problem is 2 upload fields share the same namer class.

my original namer code:

use Vich\UploaderBundle\Naming\NamerInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class SupplierFileNamer implements NamerInterface
{
public function name($obj, $field)
{
$file = $obj->fileAvatar;
if (is_null($file) == FALSE && ($file instanceof UploadedFile) == TRUE) {
$extension = $file->guessExtension();
return 'avatar_'.uniqid().'.'.$extension; <== this is the error point, after process the first field, it will escapt.
}

$file = $obj->fileBanner;
if (is_null($file) == FALSE && ($file instanceof UploadedFile) == TRUE ) {
    $extension = $file->guessExtension();
    return 'banner_'.uniqid().'.'.$extension;
}

}
}

so, my temporary solution is separate config for these multi upload fileds. that is mean "one filed one config".

vich_uploader:
db_driver: orm
storage: vich_uploader.storage.file_system
mappings:
supplier_image_avatar:
upload_destination: %kernel.root_dir%/../web/uploads/_supplier
namer: tw_shop.supplier.fileNamer.avatar <-- separate
delete_on_remove: true
delete_on_update: true
inject_on_load: false
supplier_image_banner:
upload_destination: %kernel.root_dir%/../web/uploads/_supplier
namer: tw_shop.supplier.fileNamer.banner <-- separate
delete_on_remove: true
delete_on_update: true
inject_on_load: false

Hope this message can help who has the same problem.

from vichuploaderbundle.

ftassi avatar ftassi commented on May 24, 2024

Hi @cipherchien

The main problem with your namer implementation is that you're not using the $field variable to retrieve the UploadedFile instance. Here you can find a simple NamerInterface implementation : https://gist.github.com/4325868
Look how I've used the $field variable to retrieve the correct image from the entity.

from vichuploaderbundle.

cipherchien avatar cipherchien commented on May 24, 2024

Oops!

My bad, I didn't checkout the code examples carefully.
Thank you for your description.

from vichuploaderbundle.

ftassi avatar ftassi commented on May 24, 2024

👍

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.