8

I'm using Drupal 8 with Webform module.

I want to allow users to upload one or several files when filling the form. Is it possible with Drupal 8? May be some additional module required for this?

3 Answers 3

22

You need to enable webform UI, then set in your sites/default/settings.php file the privates files directory path: $settings['file_private_path'] = 'sites/default/files/private'; where 'sites/default/files/private' is your privates files directory path. You can choose another directory. And give to this directory the write permission. Then clear all caches. Now you can add files fied in your webform while adding new element. In the popup that appears, typing file, you will see all files type like image, audio, etc. Webform new element form

5
  • Awesome. Thank you so much. Jun 28, 2019 at 7:33
  • 1
    Note that an example of a more secure path would be '../files' or '../private'
    – mbomb007
    Nov 4, 2020 at 16:47
  • Awesome! Worked like a charm on Drupal 9. Mar 8, 2022 at 14:49
  • 2
    Is this answer still relevant? I'm not getting any file element types.
    – Kartagis
    Dec 14, 2022 at 12:30
  • I also had to make the file available as an element type within the admin configuration settings section of all webforms (/admin/structure/webform/config/elements)
    – neuquen
    Jan 23 at 20:26
2

Yes, you can allow users to upload files to the webform by adding a new "managed_file" form element into the "Elements (YAML)":

enter image description here

This is provided that you have your public and private file paths set, which will otherwise throw a notice telling you to set those up.

1
  • 2
    Can I add 'file_upload' field using Webform UI?
    – MiSHuTka
    Apr 13, 2017 at 15:13
2

Another solution of yaml configuration for images in order to upload a file:

picture:
  '#type': image_file
  '#title': Photo
  '#file_extensions': 'gif jpg png svg jpeg'
  '#multiple': True

You can install the module Webform UI to do this in the interface...

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.