Hi,

Currently the file upload component allows to choose the scheme where to upload the files, but not a sub-directory of them (unless I'm mistaken). Would it be possible to choose a directory (which would be able to use token depending on current user to have some complex business logic)?

Comments

Simon Georges created an issue. See original summary.

jrockowitz’s picture

Status: Active » Closed (won't fix)
StatusFileSize
new146.77 KB

I deliberately did not expose the #upload_location property for the manage file element because it is not something anyone should customize.

The default file upload location is ://webform/WEBFORM_ID/SUBMISSION_ID, which I strongly feel is the best destination for most webforms. Tracking the webform id and submission id in the file path makes it easy to track and manage uploaded files. For example, I use this pattern to include uploaded files in an exported CSV/archived.

@Simon Georges the good news is you can easily set the #upload_location as a custom property. NOTE: This will stop uploaded files from being included in exported submissions.

Here is screen shot of the custom property...

...and you can read the API docs for more information about the #upload_location property.

http://cgit.drupalcode.org/drupal/tree/core/modules/file/src/Element/Man...

simon georges’s picture

Thanks for the fast answer! I'll see if we can use this customization, otherwise, we'll find another way ;-)

mph.arthur’s picture

There is an error [The file could not be uploaded because the destination "some/directory" is invalid.] when upload a file.

It created the folder some/directory automatically but it not allow me to upload any file.

jrockowitz’s picture

This is most likely a permissions related issue. You need to check the directories permissions. I do not recommend changing the #upload_location.

mph.arthur’s picture

My case will receipt 200 applications with photos and music files submitted with the form. I would like the photos and pictures group in specific folder base on they application, so I don't need to pull file from submission id folder one by one.

I also try the input the #upload_location "sites/default/files/private/webform/{webformID}/{submissionID}" which should be the same as default, but still get the same result.

Could you please gave some any suggestion?

kclarkson’s picture

This is interesting. I believe webform in D7 had this capability. In situations where people may want to access the files on the backend I could see why you may want organize the files. I am thinking of a situation where we different file uploads where you may want to keep them separated.

andrimont’s picture

Hello to all and thank you @jrockowitz and the maintainers for this stunning work for the Drupal ecosystem.
This post help very much to achieved a good organisation for the uploaded files.
Here's the setting :
upload_location: 'private://organised/path/[some:token]'
I understand that @jrockowitz must have good reasons for not exposing the #upload_location property for the manage file element, but for my use, it works so well that way.

andrimont’s picture

Hello @all,
I used this setting to upload files with great success :
upload_location: 'private://organised/path/[some:token]' .
But it doesn't work anymore. Instead of a nice path to the uploaded file, I have a weird and double one :
The path was :1531044/uploaded_file.jpg uid being the [current-user:uid]
I becomes :

drwxrwxr-x 2 user user 4096 Jul  3 14:06 1531044
drwxrwxr-x 2 user user 4096 Jul  3 14:06 '[current-user:uid]'

And the uploaded_file.jpg being in the very odd '[current-user:uid]' folder.
How can two folders are created one with the correct value and the other with the token ?
I tried several options like turning off the Sanitize file name. But no success to get the upload files back to the right path.