3

If I upload a contact image by editing the contact record it works. I can see the contact image, and it has a URL when viewed from the contact record that looks something like: https://example.org/civicrm/file?reset=1&filename=image_a46992b081c6ccee3e54abcfdd0ba352.jpg&mime-type=image/jpg I can click on it and it appears in a pop-up window. Lovely.

If I upload the exact same image file through a webform such that it becomes the contact image for the same contact it doesn't work. It has the URL https://example.com/civicrm/file?reset=1&filename=custom&mime-type=image/ when viewed from the contact record, and instead of seeing the image I just see the word 'custom'. Clicking on the word 'custom' brings up a little error box that reads "The file is either empty or you do not have permission to retrieve the file", neither of which are true. The database has stored the image URL as https://example.com/sites/default/files/webform/pics/image.jpg

This used to work fine on an earlier version of Civi (4.6.x). I also imported contact records with 4.6.x that had external URLs for contact images and they worked fine - i.e. were viewable from the contact record, but again, now that I've upgraded to 4.7.24 all I see is the word 'custom'.

If I reference the field in a Drupal View, it can display the image without issue.

1 Answer 1

3

Uploads via Webform are indeed broken in 4.7, but have been fixed with 5.0.

Webform CiviCRM inserts the image_URL value in the database as the path to the webform upload, e.g. /sites/default/files/webform/NNNN.ext. The CiviCRM handler (CRM/Utils/File.php) expected CiviCRM-style image URLs of the form /civicrm/contact/imagefile?photo=NNNN.ext, and so mangled the path twice, once on reading it and then when it ran getFileURL on it.

Thus, anything dependent on $imageURL would break for images uploaded through Webform or other external mechanisms.

The issue was reported on Webform CiviCRM Integration as Contact Image Upload field integration not working with 4.7, and later addressed in the related GitHub issue CRM-21778 - Contact image uploaded from drupal webform don't render on the summary page.

I was able to apply jitendrapurohit's patch from GitHub cleanly to 4.7.31; the fix is contained entirely within CRM/Utils/File.php.

5
  • Double-posted as an answer must be upvoted or accepted on one or the other before it can be used as a duplicate target.
    – choster
    Commented Mar 1, 2018 at 15:32
  • I disagree that the problem is with the webform-civicrm module. On the site I'm working on I imported a whole load of contacts where the contact image URLs refer to externally hosted image files. In Civi 4.6 this worked well. Now it's broken. That has nothing to do with webform_civicrm and everything to do with poorly thought-through changes in Civi.
    – Graham
    Commented Mar 7, 2018 at 17:23
  • Not accepted as an answer because contact images can be uploaded via webform_civicrm or by importing image URLs - it's just that Civi can no longer handle these URLs, where it used to be able to.
    – Graham
    Commented Mar 7, 2018 at 17:25
  • 1
    Looks like this is being addressed: issues.civicrm.org/jira/browse/CRM-21778
    – Graham
    Commented Mar 7, 2018 at 17:28
  • Apologies. On re-reading your answer I concur. On first reading I thought you had indicated that it wasn't a Civi problem, as you had referenced the issue reported in the Webform_CiviCRM issue queue. My bad.
    – Graham
    Commented Mar 9, 2018 at 10:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.