Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Currently when a file is uploaded the webform module will automatically add it in a folder named after the submission ID, under private:webform/WEBFORM_KEY
.
So, you end up with a structure like:
$ tree
.
├── 301
│ └── file_name.jpg
├── 302
│ └── file_name.jpg
├── 303
│ └── file_name.jpg
├── 304
│ ├── file_name1.jpg
│ ├── file_name2.jpg
│ └── file_name3.jpg
└── _sid_
I suggest to give the option to admins to decide whether they want this structure or an option to save all files under one folder, without the subfolders.
With #2941286: Rename file uploads for v8.x commited we have control over the filename anyway, so using subfolders for every submission might not be needed for all projects.
Comment | File | Size | Author |
---|---|---|---|
#4 | Screen Shot 2018-02-08 at 7.25.02 AM.png | 43.5 KB | jrockowitz |
Comments
Comment #2
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThis change would break the exporting of uploaded files into a zipped archive which is a key feature. By using 'webform/WEBFORM_KEY' as the upload path we are able to copy and very quickly zip all the files uploaded for a single submission.
The workaround/solution is you can set the #upload_location as a custom element property and chose the upload folder for your files.
Comment #3
bserem CreditAttribution: bserem at zehnplus commentedI didn't understood the part with the custom element, but I guess if someone wants the files stored in a specific location then this would be fine for his downloaded archive too.
Comment #4
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedThe zip archiving only looks for files stored in webform/WEBFORM_KEY/SID.
The #upload_location would be set as a custom property.
Comment #5
b.khouy@jrockowitz thank you for #upload_location property suggestion, does the Yaml field Custom properties support tokens?
Also for your #2 comment, I think we can customize file upload location without break zipping uploaded files. Lets say we want to add a textfield field with tokens support to the webform settings tab, that textfield will store the directory within the files should be stored my-directory for example, and implicitly prefix that directory by webform/WEBFORM_KEY and suffix it with /SID then the final upload folder will be webform/WEBFORM_KEY/my-directory/SID, does this logic either break downloading uploaded files process, what do you think?
Comment #6
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedUsing
webform/WEBFORM_KEY/my-directory/SID
will break the downloading of exported files.Comment #7
MikaT CreditAttribution: MikaT at Siili Solutions commentedNote that the custom properties doesn't seem to support tokens so one might need to extend the
WebformManagedFileBase
and in that new class override thegetUploadLocation
.As I needed token support, I did it so that I created new WeformElement extending the WebformManagedFileBase that introduced new field where the upload location can be entered. Then in
getUploadLocation
get the new field value from $element, run $this->replaceTokens($element) and then call the parent getUploadLocation.Remember to create an element matching the ID of the webform element