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?


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

  • Awesome. Thank you so much. – Saeed Afzal Jun 28 '19 at 7:33
  • 1
    Note that an example of a more secure path would be '../files' or '../private' – mbomb007 Nov 4 '20 at 16:47

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
    Can I add 'file_upload' field using Webform UI? – MiSHuTka Apr 13 '17 at 15:13

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

  '#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, privacy policy and cookie policy

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