When uploading files using the file_entity's own file overview, the directory is fixed at ''. It should be possible to set a custom directory for files uploaded, if not already specified by some other modules.

CommentFileSizeAuthor
#32 use-file_entity_default_file_directory-1997208-33.patch2.61 KBjoseph.olstad
#31 use-file_entity_default_file_directory-1997208-32.patch2.67 KBjoseph.olstad
#30 use-file_entity_default_file_directory-1997208-31.patch2.12 KBjoseph.olstad
#29 use-file_entity_default_file_directory-1997208-30.patch2.03 KBjoseph.olstad
#18 use-file_entity_default_file_directory-1997208-18.patch551 bytesgmclelland
PASSED: [[SimpleTest]]: [MySQL] 882 pass(es). View
#15 use-file_entity_default_file_directory-1997208.patch551 bytesgmclelland
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View
#14 set-a-file-directory-1997208-14.patch2.23 KBgmclelland
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View
#12 file_entity-set_a_default_file_directory_for_upload_form-1997208-12.patch2.17 KBgmclelland
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View
#11 file_entity-set_a_default_file_directory_for_upload_form-1997208-11.patch1.8 KBgmclelland
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View
#9 file_entity-set_a_default_file_directory_for_upload_form-1997208-9.patch1.68 KBgmclelland
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View
#2 file_entity-set_a_default_file_directory_for_upload_form-1997208-2.patch1.63 KBesbenvb
PASSED: [[SimpleTest]]: [MySQL] 823 pass(es). View
#1 file_entity-set_a_default_file_directory_for_upload_form-1997208-1.patch1.63 KBesbenvb
None View
Members fund testing for the Drupal project. Drupal Association Learn more

Comments

esbenvb’s picture

This patch provides a setting form in admin/config/media/file-system and reads the variable when building the destination path.

Please remember to pass the proper git attribution when porting the patch, as mentioned on http://drupal.org/user/989064

esbenvb’s picture

Version: 7.x-2.0-unstable6 » 7.x-2.x-dev
FileSize
1.63 KB
PASSED: [[SimpleTest]]: [MySQL] 823 pass(es). View

Here is a patch for the current dev release.

aaron’s picture

Status: Needs review » Reviewed & tested by the community

This works as advertised.

Dave Reid’s picture

I'm not 100% on this being useful compared to if we had a little more work put into upload destination options. I believe we either need to allow people to choose where their file is uploaded on the file/add page itself, or this needs to be exposed as an option in the file types.

Dave Reid’s picture

I filed a new issue for the direction I would like to go in: #2000934: Allow selection of which folder a file is to on the file/add form.

esbenvb’s picture

Dave, there might be situations where you don't want users to choose the paths themselves, but you want the path of all uploaded files to comply with the overall file system structure. I.e. in our example we use tokens in the path for putting files into folders based on upload dates.

This is another relevant usecase where it makes very little sense to let the user specify a file path himself: http://drupal.org/node/1997272

Edit: An option for the user when uploading the file would be fine, but even then, it would be good to have some overruling control if you don't want the files spread all over /sites/default/files... Consider that feature as an addition to my patch, not an alternative.

Dave Reid’s picture

Status: Reviewed & tested by the community » Needs review

I don't see why the use case in #6 isn't covered by https://drupal.org/project/fe_paths already.

gmclelland’s picture

FYI.... In the meantime I was looking for something simple so I tried the patch in #2 and it no longer applies to the latest 2.x-dev

git apply -v file_entity-set_a_default_file_directory_for_upload_form-1997208-2.patch
Checking patch file_entity.module...
error: while searching for:
  }
  return fnmatch($pattern, $string);
}

error: patch failed: file_entity.module:2178
error: file_entity.module: patch does not apply
Checking patch file_entity.pages.inc...
Hunk #1 succeeded at 411 (offset 7 lines).
gmclelland’s picture

FileSize
1.68 KB
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View

Here is a reroll of #2 in case @Dave Reid changes his mind for something simple. ;-)

I'm not sure if this is missing the token popup dialog? That goes with "this field supports tokens."

gmclelland’s picture

Just checked and the patch in #2 and #9 doesn't include the token dialog.

gmclelland’s picture

FileSize
1.8 KB
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View

Here is an untested reroll of #2 that should add the token browser.

gmclelland’s picture

FileSize
2.17 KB
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View

Patch in #11 didn't work. This patch includes a conditional check for the token module.

gmclelland’s picture

Well I'm not sure why, but I can't get the link to show that say's something like "Browse the available tokens" to show up. I did test the patch on simplytest.me and it allowed me to upload a file to specified default directory.

I was trying to get the token dialog code from http://drupalcode.org/project/media.git/commitdiff/b350d22?hp=3f4c786536...

gmclelland’s picture

FileSize
2.23 KB
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View

Reroll of #12 to work with the latest dev.

gmclelland’s picture

Issue summary: View changes
FileSize
551 bytes
PASSED: [[SimpleTest]]: [MySQL] 874 pass(es). View

Here is a new simple patch that makes any files uploaded at file/add use the file entity default directory. Right now all files uploaded to file/add go into the root of the files directory.

tsmulugeta’s picture

When I tried running your patch it didn't work. I
(1) Went into the file entity folder,
(2) Uploaded your patch there,
(3) And then ran this command in the command line: $ git apply -v use-file_entity_default_file_directory-1997208.patch

I do have both Git and Drush installed on my server.

I got this message:

use-file_entity_default_file_directory-1997208.patch:10: trailing whitespace.
    'file_directory' => variable_get('file_entity_default_file_directory', ''),
Checking patch file_entity.pages.inc...
warning: file_entity.pages.inc has type 100755, expected 100644
error: while searching for:
function file_entity_upload_destination_uri(array $params, array $data = array()) {
  $params += array(
    'uri_scheme' => file_default_scheme(),
    'file_directory' => '',
  );

  $destination = trim($params['file_directory'], '/');

error: patch failed: file_entity.pages.inc:431
error: file_entity.pages.inc: patch does not apply

Please advise. Thanks!

markgifford’s picture

tsmulugeta: I assume you mean the patch in #15. There are a few patches in this issue. The patch is 10 months old, and the underlying code it patches has changed in the meantime, so it's now out of date. You'd need to reroll the patch against the current -dev branch, and then it should apply. For this specific patch, though, you might be better off just manually changing the code yourself because it only changes one line.

Again assuming you're using latest 2.0-beta1, the line you want is 494 of file_entity.pages.inc. It needs to be changed from
'file_directory' => '',
to
'file_directory' => variable_get('file_entity_default_file_directory', ''),

gmclelland’s picture

FileSize
551 bytes
PASSED: [[SimpleTest]]: [MySQL] 882 pass(es). View

Here is a patch that should work against the 2.x-dev.

colan’s picture

Title: It should be possible to set a file directory for files uploaded using the /file/add form » Specify a fixed custom file directory for use with the /file/add form

Updating title to reflect the fact that this doesn't actually allow users to choose a directory per file uploaded. That's #2000934: Allow selection of which folder a file is to on the file/add form.

Also, marked #2109673: Specifying upload path for /file/add as a duplicate.

colan’s picture

Status: Needs review » Needs work

The last patch is attempting to grab data from a variable that was never set so the result will always be the root of the files directory. It looks like the code for setting the variable got lost after #14. It would need to be brought back.

In other news, I've got a preliminary patch for #2000934: Allow selection of which folder a file is to on the file/add form. Please review.

SocialNicheGuru’s picture

if using http://drupal.org/project/fe_paths will the file_entity path be the appropriate fe_path based on file type?

sheldonkreger’s picture

@socialNicheGuru: Yes, FE Paths settings are respected on all upload areas, including the upload at /file/add, file attachment fields, wysiwyg buttons, etc.

Without FE Paths, I experience this bug only at file/add. All my file field config is respected, but there is no config for /file/add

WayneDyck’s picture

I just updated to version 7.x-2.1 and will still need to apply this patch again because files uploaded using /file/add continue to be saved at the root of the "files" directory. I am a little surprised this issue hasn't received more traction over the years since it was first reported.

joseph.olstad’s picture

Status: Needs work » Closed (duplicate)
Parent issue: » #2000934: Allow selection of which folder a file is to on the file/add form
WayneDyck’s picture

@joseph.olstad thanks, however, I don't want to provide users with a choice of where their uploaded file goes. I simply use something like,

[current-date:custom:Y]/[current-date:custom:m]/[current-date:custom:d]

set with tokens in the "File entity: Default file directory" and the file is saved in a date based directory.

If I give the users the ability to create and name directories it becomes a nightmare.

joseph.olstad’s picture

yes agreed, keep using tokens if that's working for you.
if you have a patch for us, please share it.
or if you have the configuration steps for this please share it with us and we can add it to the documentation.
Thanks

joseph.olstad’s picture

Status: Closed (duplicate) » Active
joseph.olstad’s picture

which patch are you using?
have you tested it with the latest release file_entity 7.x-2.4 ?

joseph.olstad’s picture

Status: Active » Needs review
FileSize
2.03 KB

new patch for 7.x-2.x

joseph.olstad’s picture

new patch again, this one adds text description suggesting token config [current-date:custom:Y]/[current-date:custom:m]/[current-date:custom:d]

joseph.olstad’s picture

joseph.olstad’s picture

WayneDyck’s picture

I'm using the changes defined in #14. I manually add them to each official release which comes out before I push the updated module into production. I am going to apply the modifications against file_entity 7.x-2.4 this afternoon.

Did you still need me to make a patch as it looks like you have one in #32.

joseph.olstad’s picture

Manually apply ? Ever try the patch command?
Patch 33 should do the job, let me know how it works for you.

WayneDyck’s picture

I wasn't patching the original source; just the downloaded release module. If you are not working with the checked out source the patch command will not work, correct?

I will try patch 33 and let you know. Thanks.

WayneDyck’s picture

Patch 33 works fantastic. I think it makes a lot of sense to have the configuration for the "Default file directory" as an option under "File settings". Nice.

Also like the, "Suggest using: [current-date:custom:Y]/[current-date:custom:m]/[current-date:custom:d]" as an suggested option. If you are on a site with a lot of daily uploads it will definitely keep the number of files per directory manageable.

Thanks for doing that.