-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload Field #396
Comments
@boonkerz check out updated Upload docs section 4 Edit your entity class Upload type extends Collection type, which needs |
Hey should i use collection? Because i use the single_upload type: |
@loostro I'm trying to get single_upload work and create a cookbook entry on it but I can't figure out the last step that involves editing of the generator.yml file. When you got some time, can you please have a look into my draft document and advise where to go from here? Thanks, It's very much appreciated. |
# generator.yml
image:
label: Bild
formType: single_upload
dbType: string
addFormOptions:
data_class: Symfony\Component\HttpFoundation\File\File # Entity:
/**
*
* @Vich\UploadableField(mapping="product_image", fileNameProperty="image_path")
*/
private $image;
/**
* @var string $image
*
* @ORM\Column(name="image_path", type="string", length=255, nullable=true)
*/
private $image_path; |
@battika see @boonkerz 's post above, for Vich uploader to work you must add About the generator.yml config, here is a working example from my project: image:
label: label.image
formType: single_upload
dbType: string
addFormOptions:
nameable: imageLabel
data_class: Symfony\Component\HttpFoundation\File\File and the entity behind it: /**
* @Assert\File(
* maxSize="12M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Assert\Image(
* minWidth = 280,
* minHeight = 100
* )
* @Vich\UploadableField(mapping="category_image", fileNameProperty="imagePath")
*/
protected $image;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $imageLabel;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $imagePath; and my vich_uploader config: vich_uploader:
db_driver: orm
gaufrette: false
storage: vich_uploader.storage.file_system
mappings:
category_image:
uri_prefix: /media/category/image
upload_destination: %kernel.root_dir%/../web/media/category/image
namer: vich_uploader.namer_uniqid
inject_on_load: true
delete_on_remove: true
delete_on_update: true As you can see I used Thats why I introduced the (optional) nameable option. You can specify a property in which original filename info will be saved. Also, this filename can be edited, so if you've uploaded In future i hope to push a PR to Vich bundle which will allow to use a property to serve the file back to the user with our stored filename. Right now downloading that file will give user a |
@loostro @boonkerz Thanks very much for your quick help. I set up everything identical to @loostro 's configuration but when I set up my generator.yml like this: new:
params:
title: New object for ProductBundle
display:
- name
- price
- image
actions:
save: ~
list: ~ I'm getting an error: When I replace Can you please help what I'm doing wrong? Thank you. |
@battika you should create getters and setters for your properties: for each property (e.g.
for
You can write them on your own or simply use |
And we have the same Issues: |
i think dustin10/VichUploaderBundle#106 will solve your problem (useing preUpdate event) |
Yea but is not merged :( |
@loostro thanks I'm aware of getters and setters for some reason they never get created for $image, even when I specified /**
* @Assert\File(
* maxSize="12M",
* mimeTypes={"image/png", "image/jpeg", "image/pjpeg"}
* )
* @Vich\UploadableField(mapping="product_image", fileNameProperty="imagePath")
*
* @var File $image
*
*/
protected $image; So, I had to create the getter and setter manually. Thanks for the tip, it works like a charm now. |
good! i hope you like this widget =) its one of my favourite =) |
@loostro thank you, I like it very much |
Hey,
after upload an file the follow error occurs:
The form's view data is expected to be an instance of class Symfony\Component\HttpFoundation\File\File, but is a(n) string. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms a(n) string to an instance of Symfony\Component\HttpFoundation\File\File.
I think its related to symfony 2.2 or?
Regards
The text was updated successfully, but these errors were encountered: