Comments (7)
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.
Just add annotated property to the entity, you can have as many files as you want in your entity
from vichuploaderbundle.
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.
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.
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.
Oops!
My bad, I didn't checkout the code examples carefully.
Thank you for your description.
from vichuploaderbundle.
👍
from vichuploaderbundle.
Related Issues (20)
- delete_on_update does not remove the original file HOT 2
- UnitializedPropertyException when using nullable UploadableField as promoted property HOT 3
- Warning: file_exists(): open_basedir restriction in effect. Use relative paths?
- Support for Symfony 7 HOT 6
- Entity association not deleted when removing file HOT 3
- 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
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.