Answers.Body: <p>As mentioned in comment, I was able to get it to work as expected/desired by creating a webform that started with only a Name and the elements to link file to the Civi contacts.  Then I recreated the rest of the webform elements and dropped a document element.  Again, not sure if the document element was the problem or some other change with the new webform creation.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-27T19:15:09.307Z
Answers.Text: We have several sites with D9 webforms including files - i don't recall hitting this issue but will ask around the Fuzion team - glad you found a workaround
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-27T17:01:22.563Z
Answers.LastActivityDate: 2023-09-27T17:01:22.563Z
Answers.UserDisplayName: Dave T
Answers.Body: <p>There is a way, at least if you are using the <a href="https://docs.civicrm.org/formprocessor/en/latest/" rel="nofollow noreferrer">webform integration based on form processors and CMRF</a> (and not the &quot;built in CiviCRM &lt;-&gt; Webform&quot; integration - not sure if it works there).</p>
  <ul>
  <li>Create a form processor input oft the type &quot;file&quot;</li>
  <li>Create a form processor action &quot;Upload file to a custom field&quot;</li>
  </ul>
  <p>This allows the form processor to &quot;fetch&quot; any file if provided with an url and store it in CiviCRM. The problem is that drupal stores files in the private file system so the form procressor is not allowed to fetch the file by default.</p>
  <p>You can work around that problem by submitting an url that contains an authorization token from Drupal to the form processor:</p>
  <ul>
  <li>Create a corresponding file field in Drupal Webforms</li>
  <li>In Drupal Webform configuration, navigate to the file field's settings for the submission display</li>
  <li>in the dropdown, choose &quot;custom&quot;</li>
  <li>in &quot;Item format custom HTML&quot; enter:</li>
  </ul>
  <blockquote>
  <p><code>&lt;a href=&quot;{{ item.url }}?token={{ token }}&quot; target=&quot;_blank&quot;&gt;{{ item.name }}&lt;/a&gt;</code></p>
  </blockquote>
  <p>This should pass an url to the form processor which allows it to &quot;fetch&quot; the file. I am not 100% sure if some global webform-settings or Drupal permissions need to be adapted as well but I think not.</p>
  <p>All of this can be a bit hard to set up and debug but it should work. Make sure you have the latest releases of all components (Formprocessor, CMRF, Webform...).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-09-27T12:14:25.943Z
Answers.LastActivityDate: 2023-09-27T12:14:25.943Z
Answers.UserDisplayName: Fabian
Body: <p>Using Drupal 9 webform to upload a file and attach to Civi contact.   (This has worked well for D7 and Civi.)</p>
  <p>D9 will not render the file upload element unless there is a private folder in Drupal.  But then the uploaded file is not attached to Civi contact (using custom file field in Civi) but rather stored in Drupal private folder.</p>
  <p>Is there a way to do this with D9 as it has worked for D7?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-26T23:55:30.473Z
Comments.Text: Do you need the file to be in a contact custom field or would it be enough for someone just to have a link to it? If the latter, then one option is have the webform create an activity on the contact, and choose one of the options like "Include link to view webform submission in activity details".
Comments.UserDisplayName: Demerit
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-09-27T16:58:52.787Z
Comments.Text: Thanks,  was able to get it to work as in D7 by removing a document element that was used in the webform before the File link elements.   II can only guess as to why that made a difference but it did.
Comments.UserDisplayName: Dave T
Tags: <webform-civicrm><files><upload>
Title: Uploading file from Drupal webform to Civi file field
ThreadText: # Uploading file from Drupal webform to Civi file field
  
  (Asked by: username_0 on 2023-09-26)
  
  Using Drupal 9 webform to upload a file and attach to Civi contact. (This has worked well for D7 and Civi.)
  
  D9 will not render the file upload element unless there is a private folder in Drupal. But then the uploaded file is not attached to Civi contact (using custom file field in Civi) but rather stored in Drupal private folder.
  
  Is there a way to do this with D9 as it has worked for D7?
  
  **Tags:** webform-civicrm, files, upload
  
  > **Comments:**
  > **username_1**: Do you need the file to be in a contact custom field or would it be enough for someone just to have a link to it? If the latter, then one option is have the webform create an activity on the contact, and choose one of the options like "Include link to view webform submission in activity details".  
  > **username_0**: Thanks,  was able to get it to work as in D7 by removing a document element that was used in the webform before the File link elements.   II can only guess as to why that made a difference but it did.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2023-09-27. Score: 2
  
  As mentioned in comment, I was able to get it to work as expected/desired by creating a webform that started with only a Name and the elements to link file to the Civi contacts. Then I recreated the rest of the webform elements and dropped a document element. Again, not sure if the document element was the problem or some other change with the new webform creation.
  
  > **Comments:**
  > **username_2**: We have several sites with D9 webforms including files - i don't recall hitting this issue but will ask around the username_2 team - glad you found a workaround  
  
  ---
  
  ### Answer by username_3 on 2023-09-27. Score: 1
  
  There is a way, at least if you are using the [webform integration based on form processors and CMRF](https://docs.civicrm.org/formprocessor/en/latest/) (and not the "built in CiviCRM <-> Webform" integration - not sure if it works there).
  
  * Create a form processor input oft the type "file"
  * Create a form processor action "Upload file to a custom field"
  
  This allows the form processor to "fetch" any file if provided with an url and store it in CiviCRM. The problem is that drupal stores files in the private file system so the form procressor is not allowed to fetch the file by default.
  
  You can work around that problem by submitting an url that contains an authorization token from Drupal to the form processor:
  
  * Create a corresponding file field in Drupal Webforms
  * In Drupal Webform configuration, navigate to the file field's settings for the submission display
  * in the dropdown, choose "custom"
  * in "Item format custom HTML" enter:
  
  > `<a href="{{ item.url }}?token={{ token }}" target="_blank">{{ item.name }}</a>`
  
  This should pass an url to the form processor which allows it to "fetch" the file. I am not 100% sure if some global webform-settings or Drupal permissions need to be adapted as well but I think not.
  
  All of this can be a bit hard to set up and debug but it should work. Make sure you have the latest releases of all components (Formprocessor, CMRF, Webform...).
  
  
  ---
  
  