Support from Acquia helps fund testing for Drupal Acquia logo

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

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

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

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

gmclelland’s picture

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

Reroll of #12 to work with the latest dev.

gmclelland’s picture

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

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

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.

WayneDyck’s picture

What needs to happen in order to get patch 33 committed? Do I need update the issue and mark it as "reviewed?"

joseph.olstad’s picture

Status: Needs review » Reviewed & tested by the community

usually someone other than the patch writer will put in a review.
Ya, I've looked at it, looks pretty good but wasn't on my radar.

  • esbenvb authored 073d1c0 on 7.x-2.x
    Issue #1997208 by gmclelland, joseph.olstad, esbenvb: Specify a fixed...

  • esbenvb authored 073d1c0 on 7.x-3.x
    Issue #1997208 by gmclelland, joseph.olstad, esbenvb: Specify a fixed...
joseph.olstad’s picture

Too bad that this was overlooked for 7.x-2.5 , however, there's always 7.x-2.6, tags are free.

joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed
WayneDyck’s picture

No worries. In retrospect I should have moved it into "Reviewed..." after I applied it and verified it worked. Will be sure to do that for any future patches.

Thanks.

vchen’s picture

Thanks for getting this working! I have 7.x-2.6 installed and I can't get anything with [file:xxx] to work as a token in the Default file directory. [current-date:custom:Y] and other date tokens work just fine. I'd like to organize files by year/filetype.

It just makes the year folder and then a subfolder called "[file:type]" or whatever token I choose. It seems the treat the token as a literal string of text.

joseph.olstad’s picture

@vchen please feel free to open a new issue for your new request to enhance this functionality, you can open a new issue, link it to this one, mark it as 'needs review' when you've got something to review.

fredcy’s picture

We have been using the filefield_paths module for years to assign specific paths to uploaded files. This recent change to field_entity seems to conflict with filefield_paths.

Where we have file fields (attachments) associated with content types we used filefield_paths to set the "File path" setting to be "upload" for each type, causing uploaded attachments to be stored directly within the sites/default/files/upload directory. But after updating file_entity to version 7.x-2.6 (and not changing any config settings) such uploaded files are ending up in the sites/default/files/filefield_paths directory instead. I suspect that is because the "Temporary file location" config setting for filefield_paths (its only setting, in fact) has a value of "public://filefield_paths".

So this causing a problem for us because we don't want the uploaded files to end up in that "filefield_paths" directory. They should go into the "upload" directory as they have been.

fredcy’s picture

About the above -- nevermind. Uploaded files are actually ending up in our intended "upload" directory. I think in my earlier tests I must have uploaded the file attachment but not saved the content item itself. Doing that seems to leave the uploaded file in that temporary directory. Once I save the item the file attachment gets moved to the "upload" directory as we want. Sorry for the confusion.

joseph.olstad’s picture

thanks for reviewing and reporting, good to know it's working out.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.