Closed fredleput closed 9 years ago
Hi,
Oups I forgot in my documentation to explain how to bind the uploaded file with the entity. I will add it tonight.
You must create an attribute type text :
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @var string
*/
protected $picture;
Then in your form you can add the field type image ajax :
$builder->add('picture', 'jb_image_ajax', array(
'endpoint' => 'my_endpoint_name',
'img_width' => 100
));
Note that the filename will be stored in DB. Then using the table file_history, we can retrieve the endpoint used to upload it and so find it in the file storage in order to generate an url.
What is missing is a custom validator to be sure that somebody else cannot submit an existing filename owned by another user. I am going to add it this weekend.
I am waiting for your feedback.
thx try thathis and go back...
Sorry, i have an entity Location in which i have the property image (string) with getter and setter. in my LocationType i have : $builder ->add('categorie') ->add('proprietaire') ->add('adr1') ->add('adr2') ->add('cp') ->add('ville') ->add('situation') ->add('ouverture') ->add('capacite') ->add('savplus') ->add('classe') ->add('classement') ->add('actif') ->add('site') ->add('image', 'jb_image_ajax', array( 'img_width' => 400, 'endpoint' => 'gallery' )) ; and i have the following error :
Catchable Fatal Error: Argument 1 passed to Jb\Bundle\FileUploaderBundle\Service\FileHistoryManager::getUrl() must be an instance of Jb\Bundle\FileUploaderBundle\Entity\FileHistory, null given
It seems you have form data in your field image
(lookup the hidden input text in the field HTML or var_dump($form->getData()) in controller after isValid) but you don't have the FileHistory entry matching this filename in the table jb_filehistory
. Could you check this ?
I will add check for this case this evening.
"but you don't have the FileHistory entry matching this filename in the table jb_filehistory" No indeed ther's no relation between this tables but there should have one bettween image property and a fileHistory entry ?
You don't really need the doctrine relation. It would be a security for consistency but usually when uploading the image using the ajax route, the entry with uploaded file original name, generated name and endpoint used should be created in the table. If it didn't, you maybe have a php error somewhere when the uploaded the file.
Does the table jb_filehistory
exists ? (have you runned the d:s:u command ?)
Yes the table jb_filehistory exists whith 4 fields. What the d:s:u command ?
Sorry i'm a noob but where can i find the result of var_dump($form->getData()) since i get this error
You have content in there ?
d:s:u is a shortcut for doctrine:schema:update.
In your action of your controller, you should have something like this :
if ($form->isValid()) {
// Add the var_dump to see what you have in your form after submit
var_dump( $form->getData());die();
}
Your error occured because you have data in the image field (maybe because the field already existed before adding this bundle or because you uploaded a picture but an error occured on upload when trying to create the entry in file history) and when we search the file history table for the entry corresponding to the data it does not find it.
You're right the field image already existed. I change it's name to picture (getter and setter also). In my Location type i change the field image to picture. i update my database (d:s:u --force). All is alright. I clear the cache. i retry and still get the same error.
i can't submit the form since i get the error when it should appear so the var_dump isn't executed...
I have no content in jb_filehistory table...
No what I mean is that : do you have existing data in this field image/picture ?
No there's nothing in it
Nothing as NULL or empty string "" ?
empty string i think i can update my DB to put it at NULL
Yeah, do that and it should work
Yes that's it after update my DB the form appears
Sorry, but now i have this error "unknown resolver". A configuration problem i think...
Yeah, look at the getting started page : https://github.com/jbouzekri/FileUploaderBundle/blob/master/Resources/doc/base/getting_started.md
You have a full configuration for the jb_image_ajax field type to work.
Resolver is configured in jb_file_uploader. You should have a resolver which match the gaufrette filesystem used in the oneup configuration.
I tested it 2 days ago and normally this configuration in getting started works as it is. You can copy paste it. Create a folder web/uploads. Give apache read and write rights on web/uploads, clear cache and go.
I am waiting for your feedback if you have any issue or misunderstanding.
my folder web/uploads is writable for www-data group I think i copy / paste this configuration from the getting started section :
#oneup_uploader
oneup_uploader:
mappings:
gallery:
frontend: blueimp
#liip_imagine
liip_imagine:
filter_sets:
original: ~
twig:
form:
resources:
- 'JbFileUploaderBundle:Form:fields.html.twig'
knp_gaufrette:
stream_wrapper: ~
adapters:
image:
local:
directory: %kernel.root_dir%/../web/uploads
create: true
filesystems:
image:
adapter: image
alias: image_filesystem
oneup_uploader:
mappings:
gallery:
frontend: blueimp
storage:
type: gaufrette
filesystem: gaufrette.image_filesystem
stream_wrapper: gaufrette://image/
liip_imagine:
loaders:
stream.image_filesystem:
stream:
wrapper: gaufrette://image/
filter_sets:
original: ~
thumb_from_original:
data_loader: stream.image_filesystem
quality: 75
filters:
thumbnail: { size: [120, 90], mode: outbound }
jb_file_uploader:
resolvers:
upload:
assets:
directory: uploads
endpoints:
gallery:
upload_resolver: upload
upload_validators: {}
crop_validators: {}
Remove this :
#oneup_uploader
oneup_uploader:
mappings:
gallery:
frontend: blueimp
#liip_imagine
liip_imagine:
filter_sets:
original: ~
twig:
form:
resources:
- 'JbFileUploaderBundle:Form:fields.html.twig'
In app/config.yml
, you have the following line somewhere :
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
Modify it as :
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
form:
resources:
- 'JbFileUploaderBundle:Form:fields.html.twig'
And clear cache. What does happen ? Always the unkown resolver problem ?
Sorry but yes. Thx for help ! I will go eating its 12:22 in France and i come back this afternoon.
Je suis français également si tu veux discuter dans cette langue. Aucun problème.
En effet ça sera plus facile ce qui est étonnant c'est que le fichier est uploadé. Je le retrouve dans mon dossier web/uploads ??? la table jb_filehistory se remplit... Par contre je n'ai rien dans la table de mon entité.
Bon appétit à tout, :+1:
Oui c'est normal. Ce qu'il se passe, c'est que l'upload se passe bien. Tu dois avoir le fichier avec un nom à plusieurs caractères aléatoire et son extension. L'erreur intervient lorsque le bundle essaye de générer une url pour l'affichage dans le cadre de preview.
Il cherche à utiliser un resolver vide. Quand tu as renommé to champ en picture et que tu as modifié ton FormType, tu as copié le code indiqué dans mon premier commentaire tel quel :
$builder->add('picture', 'jb_image_ajax', array(
'endpoint' => 'my_endpoint_name',
'img_width' => 100
));
Si c'est le cas alors c'est normal que ça plante. Tu dis à ce champ de formulaire d'utiliser le endpoint my_endpoint_name
mais quand tu regardes la configuration du getting started, tu as configuré un unique endpoint gallery
(cf la configuration oneup_uploader.mappings où tu as une clé gallery et jb_file_uploader.endpoints où tu retrouves cette clé gallery).
Peux tu modifier la configuration de ton formulaire ainsi :
$builder->add('picture', 'jb_image_ajax', array(
'endpoint' => 'gallery',
'img_width' => 100
));
Et surtout reprendre ton process du début : champ de formulaire vide, upload d'une nouvelle image, ...
Re... En fait la config du endpoint est OK "gallery" partout...
Peux tu m'indiquer ce que tu as dans la table file_history ?
file_name 54b7bd4e64282.jpg original_name bernard-omnes.jpg type gallery user_id 1
Et 54b7bd4e64282.jpg est bien le dernier fichier que tu as uploadé ?
Tu peux essayer un truc ?
Modifier la configuration :
jb_file_uploader:
resolvers:
upload:
assets:
directory: uploads
upload_resolver: upload
endpoints:
gallery:
upload_validators: {}
crop_validators: {}
Je reteste d'ici une heure environ... J'ai une formation à donner...
De retour, J'ai essayé avec la nouvelle config mais le problème reste le même : fichier uploadé, 1 ligne dans la table jb_filehistory (54b7de0fac085.jpg, bernard-omnes.jpg, gallery, 1) par contre rien dans la table de l'entité...
Quand tu dis rien dans la table entité, tu n'as plus eu le problème de "Unknown Resolver" ?
Si toujours le problem de resolver mais le champ picture de l'entité n'est pas renseigné
Le code de ton projet est il accessible en public ?
Je viens de me faire une installation vierge de SF en prenant la configuration du getting started je n'ai pas ce soucis ...
malheureusement non mais je peux t'envoyer un zip si tu veux
j'ai faint un targ gz avec le dosser source (src.tgz) et un avec le dossier app je te les envoi comment ?
Tu peux mettre ton composer.json aussi ?
oui bien sur je t'envoi un lien...
J'avais pas vu je le mets sur dropbox et je t'envoi le lien. du coup j'ai mis tout le projet (25 Mo)
Normalement c'est parti...
Je regarde ce soir.
OK merci pour ton aide à plus et bonne soirée...
J'ai corrigé le problème. Une régression que j'ai provoqué hier soir en travaillant sur la partie crop avec amazon s3.
Normalement tu peux faire un php composer.phar update
à la racine du projet en répondant y
quand il te demande de Discard changes
. Si tu vas sur ton action du controlleur location, tu peux cliquer sur importer un fichier, le fichier sera uploadé et une preview sera affichée dans la zone de preview. Quand tu cliqueras sur enregistrer, le champ picture sera mis à jour en base de données.
plop ? Tu as pu testé le fix ?
YES, ça fonctionne ! Par contre si je modifie le fichier photo de mon entité location l'ancienne photo est conservée dans le dossier upload et dans le table jb_filehistory. C'est normal ?
Fred.
2015-01-16 13:52 GMT+01:00 jobou notifications@github.com:
plop ? Tu as pu testé le fix ?
— Reply to this email directly or view it on GitHub https://github.com/jbouzekri/FileUploaderBundle/issues/1#issuecomment-70249523 .
Oui je n'ai pas encore trouvé de solution pour la suppression des erreurs d'upload ou des changements à l'édition. Dans un premier temps, je pense à une tache planifiée mais je ne suis pas sûr que ce soit viable. Je vais étudier ça une fois que j'aurais fini les dernières fonctionnalités nécessaires dans un mon projet (progress bar ou loading gif et lien de suppression d'une image).
Cool
Fred.
Le 16 janvier 2015 15:52, jobou notifications@github.com a écrit :
Oui je n'ai pas encore trouvé de solution pour la suppression des erreurs d'upload ou des changements à l'édition. Dans un premier temps, je pense à une tache planifiée mais je ne suis pas sûr que ce soit viable. Je vais étudier ça une fois que j'aurais fini les dernières fonctionnalités nécessaires dans un mon projet (progress bar ou loading gif et lien de suppression d'une image).
— Reply to this email directly or view it on GitHub https://github.com/jbouzekri/FileUploaderBundle/issues/1#issuecomment-70263833 .
Je ferme le ticket. N'hésites pas si tu as des questions ou des idées d'évolution.
Hi,
I try to define the image property in my entity how to ?