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.
Is there a way to designate a path if the user is simply uploading a file via the file entity upload field at: http://mydomain/file/add
All files seem to be uploaded to the files directory by default unless they are uploaded via a secondary entity like a content type, where you can designate a path with a token in the file upload field.
Comments
Comment #2
sassafrass CreditAttribution: sassafrass as a volunteer commentedComment #3
joseph.olstadin D8, check the file_entity.routing.yml for information about paths for files. Note, these are probably virtualish url locations.
I believe that you can change this in the pathauto settings in D8 , however I haven't tried this.
as for physical locations in the filesystem, not sure , haven't tried the D8 version, just looking at the branch code to tell you what I just saw. I know in D7 there's a patch that allows users to choose the physical location that I'm considering adding, however the physical location shouldn't matter to site builders so much really or to content editors so much because the entity contains that information so that the wysiwyg people don't really need to.
I'll let the D8 people weigh in on this.
Comment #4
sassafrass CreditAttribution: sassafrass as a volunteer commentedThanks for the quick response Joseph.
Just an FYI for your discussions... my particular use case is: My client doesn't want to upload files and attach them to a particular piece of content. They manage all their files using the IMCE module and link to them as needed within content/WYSIWYG. We restrict them to a sub-directory in the files folder so they aren't exposed to all the other "crap" in the files folder and to simplify their file management. If files are uploaded to the files directory by default, they won't have access to them to manage. Besides...adding tons of files to the files directory becomes unmanageable and can eventually lead to performance issues.
Thanks again for your attention.
Comment #5
sassafrass CreditAttribution: sassafrass as a volunteer commentedOh... and the other part of the use case is... we want to give them the option to upload the files this way, rather than directly via IMCE, so that we can index the files using Search API Attachments. :-)
Thanks again!
Comment #6
joseph.olstadyou might want to look at something other than IMCE to manage huge amounts of files. entity_browser , or media , or something. Not sure what is best in the D8 space. In D7 people are using the media module in this type of use case I think.
Comment #7
sassafrass CreditAttribution: sassafrass as a volunteer commented" I know in D7 there's a patch that allows users to choose the physical location that I'm considering adding" - this would be exactly what I'm looking for. :-)
Comment #8
joseph.olstadis this what you're looking for ?
#2000934: Allow selection of which folder a file is to on the file/add form
patch #35
It works well.
Comment #9
joseph.olstadas for file_entity for Drupal 8, it might be in core now for 8.4.x dev , you might want to check and see the drupal project issue queue for the 8.x branches and see if there's an existing issue that is already open for this, or maybe it exists in 8.4.x, not sure.
But for D7, its
#2000934: Allow selection of which folder a file is to on the file/add form
Comment #10
sassafrass CreditAttribution: sassafrass as a volunteer commentedThe suggestion of using pathauto with alias patterns and tokens did the trick. I created a taxonomy for users to pick a "folder" from and used the taxonomy token in the url alias pattern. Thank-you for the suggestion!I spoke too soon... this provides an aliased path to the File Entity itself. What I'm trying to do is to use a field that I can pull a token from and use with the File (Field) Paths module to designate what folder structure to actually upload the file to... for example /sites/default/files/[current-date:custom:Y]-[current-date:custom:m]/[my-field-token-folder-name]
Comment #11
joseph.olstadComment #12
sassafrass CreditAttribution: sassafrass as a volunteer commentedComment #13
joseph.olstadthere's a patch for the D7 version.
#1997208: Specify a fixed custom file directory for use with the /file/add form
I'll probably push it in soon.