Closed denys281 closed 10 years ago
Hi @denys281
I think this is obsolete now.
Please, could you confirm?
@sescandell no, I have same problem, I still need use nameble option for file upload.
OK, I'll check that issue in coming days.
Hi @denys281
Could you please copy/paste code you are using and not working? Just to know what you're trying (and wich configuration you're using in order to be sure I use the same one).
Thank you,
@sescandell
Entity:
/**
* @Assert\File(
* maxSize="10M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="news", fileNameProperty="photoFirst")
*/
public $fileFirst;
/**
* @var string
*
* @ORM\Column(name="photo_first", type="string", length=255, nullable=true)
*/
private $photoFirst;
/**
* Set photoFirst
*
* @param string $photoFirst
* @return News
*/
public function setPhotoFirst($photoFirst)
{
$this->photoFirst = $photoFirst;
return $this;
}
/**
* Get photoFirst
*
* @return string
*/
public function getPhotoFirst()
{
return $this->photoFirst;
}
In admingenerator config:
fields:
fileFirst:
label: Firs photo
formType: single_upload
dbType: string
addFormOptions:
nameable: photoFirst
data_class: Symfony\Component\HttpFoundation\File\File
...
new:
params:
title: Новини
display: [fileFirst]
actions:
save: ~
list: ~
...
My config:
vich_uploader:
db_driver: orm
gaufrette: false
storage: vich_uploader.storage.file_system
mappings:
news:
uri_prefix: /uploads/news
upload_destination: %kernel.root_dir%/../web/uploads/news
namer: vich_uploader.namer_uniqid
inject_on_load: true
delete_on_remove: true
delete_on_update: true
liip_imagine:
cache_prefix: media
filter_sets:
news:
filters:
thumbnail: { size: [276, 226], mode: outbound}
So, sometimes it works with nameable
option and sometimes no :)
We'll check that.
Thank you,
Hi @denys281
There is something I don't understand your configuration. It's like there is something "wrong". You say:
* @Vich\UploadableField(mapping="news", fileNameProperty="photoFirst")
meaning that "photoFirst" class member will be used to stock the file name to be stored in the DB
But in your generator you write:
addFormOptions:
nameable: photoFirst
you se the same field... This cannot work (IMO).
Could you please first fix that, and see after if your problem persist.
Thank you,
@sescandell without nameable options my image don't upload on server, or upload only first time, and then I can't replace it. I don't need nameable options, but I must use it.
Hi @denys281 ,
I really think you have an error on your configuration. You use the same field for different things.
photoFirst cannot be the name input and the fileNameProperty of your file.
You can see an example of ade_single_upload
here: https://github.com/sescandell/CollectionUploadSample/blob/master/src/Acme/DemoBundle/Resources/config/Product-generator.yml and see that it is working (without nameable option and with replacement).
Full project here: https://github.com/sescandell/CollectionUploadSample
Use the URI: admin/acme_demo_bundle/Product/new
Could you please also to try without the option delete_on_update
from vich?
@denys281
I had to deal with a similar behavior before and the problem was that I had forgotten to add the @Vich\Uploadable
notation at the top of the class (entity) definition. I am using the type now, and it's working flawlessly.
@satiricon in my case I have @Vich\Uploadable
@sescandell I tested your example and I find what was wrong in my case.
I have no any setters and getters for public $fileFirst
. I add next like in your example
/**
*
* @return File
*/
public function getFileFirst()
{
return $this->fileFirst;
}
/*
* Set picture file as $file
*
* @param File $file
* @return Product
*/
public function setFileFirst(File $file = null)
{
$this->file = $fileFirst;
if ($file) {
$this->photoFirst = uniqid();
}
return $this;
}
And all works :) thank you!
@denys281
Good to know ;)
I think we should propose to VichUploader to use PropertyAccessor whereas guessing setters and getters.
@sescandell and it will be cool create new demo site for avocode form extension and admingenerator, with all features :)
I'll try to do something : https://github.com/sescandell/AvocodeFormExtensionSample
@sescandell if you need help with coding or hosting I can help.
@sescandell issue in Vich The file is not updated if there are not other changes in the entity
Option
nameble
is required forsingle_upload
widget. Without it file did not upload or upload but in strange way (sometimes all ok, sometimes we can upload only first time, and than we can not replace it). So when I upload image, I have input where user can store own name for file, but I usenamer
, so I don't want allow user edit file name (after submit name change). So maybe we can make one option that just hide input? It is very simple remake it inpreview.html.twig