Answers.Body: <p>Uploads via Webform are indeed broken in 4.7, but have been fixed with 5.0.</p>
  
  <p>Webform CiviCRM inserts the image_URL value in the database as the path to the webform upload, e.g. <code>/sites/default/files/webform/NNNN.ext</code>. The CiviCRM handler (CRM/Utils/File.php) expected CiviCRM-style image URLs of the form <code>/civicrm/contact/imagefile?photo=NNNN.ext</code>, and so mangled the path twice, once on reading it and then when it ran getFileURL on it.</p>
  
  <p>Thus, anything dependent on $imageURL would break for images uploaded through Webform or other external mechanisms.</p>
  
  <p>The issue was reported on Webform CiviCRM Integration as <em><a href="https://www.drupal.org/project/webform_civicrm/issues/2927260" rel="nofollow noreferrer">Contact Image Upload field integration not working with 4.7</a></em>, and later addressed in the related GitHub issue <em><a href="https://github.com/civicrm/civicrm-core/pull/11681" rel="nofollow noreferrer">CRM-21778 - Contact image uploaded from drupal webform don't render on the summary page</a></em>.</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-01T15:32:05.047Z
Answers.Text: [Double-posted](https://civicrm.stackexchange.com/a/22946/75) as an answer must be upvoted or accepted on one or the other before it can be used as a duplicate target.
Answers.UserDisplayName: choster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-07T17:23:51.270Z
Answers.Text: 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.
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-07T17:25:49.567Z
Answers.Text: 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.
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-07T17:28:10.190Z
Answers.Text: Looks like this is being addressed: https://issues.civicrm.org/jira/browse/CRM-21778
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-09T10:56:32.660Z
Answers.Text: 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.
Answers.UserDisplayName: Graham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-01T15:31:05.920Z
Answers.LastActivityDate: 2018-04-27T02:39:59.410Z
Answers.LastEditDate: 2018-04-27T02:39:59.410Z
Answers.UserDisplayName: choster
Body: <p>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:
  <a href="https://example.org/civicrm/file?reset=1&amp;filename=image_a46992b081c6ccee3e54abcfdd0ba352.jpg&amp;mime-type=image/jpg" rel="nofollow noreferrer">https://example.org/civicrm/file?reset=1&amp;filename=image_a46992b081c6ccee3e54abcfdd0ba352.jpg&amp;mime-type=image/jpg</a>
  I can click on it and it appears in a pop-up window. Lovely.</p>
  
  <p>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 <a href="https://example.com/civicrm/file?reset=1&amp;filename=custom&amp;mime-type=image/" rel="nofollow noreferrer">https://example.com/civicrm/file?reset=1&amp;filename=custom&amp;mime-type=image/</a>
  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 <a href="https://example.com/sites/default/files/webform/pics/image.jpg" rel="nofollow noreferrer">https://example.com/sites/default/files/webform/pics/image.jpg</a></p>
  
  <p>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'.</p>
  
  <p>If I reference the field in a Drupal View, it can display the image without issue.</p>
  
Tags: <webform-civicrm><contact-image>
Title: Can contact images be uploaded other than by editing a contact record?
ThreadText: # Can contact images be uploaded other than by editing a contact record?
  
  (Asked by: username_0 on 2017-10-09)
  
  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.
  
  **Tags:** webform-civicrm, contact-image
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-01. Score: 3 | Accepted answer
  
  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](https://www.drupal.org/project/webform_civicrm/issues/2927260)*, and later addressed in the related GitHub issue *[CRM-21778 - Contact image uploaded from drupal webform don't render on the summary page](https://github.com/civicrm/civicrm-core/pull/11681)*.
  
  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.
  
  > **Comments:**
  > **username_1**: [Double-posted](https://civicrm.stackexchange.com/a/22946/75) as an answer must be upvoted or accepted on one or the other before it can be used as a duplicate target.  
  > **username_0**: 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.  
  > **username_0**: 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.  
  > **username_0**: Looks like this is being addressed: https://issues.civicrm.org/jira/browse/CRM-21778  
  > **username_0**: 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.  
  
  ---
  
  