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.

Files: 
CommentFileSizeAuthor
#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
Test request sent.
[ View ]

Comments

esbenvb’s picture

StatusFileSize
new1.63 KB
Test request sent.
[ View ]

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
StatusFileSize
new1.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

StatusFileSize
new1.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

StatusFileSize
new1.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

StatusFileSize
new2.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

StatusFileSize
new2.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
StatusFileSize
new551 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

StatusFileSize
new551 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