Allow setting directory per-node type

webchick - June 15, 2007 - 16:35
Project:Upload path
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

For example, we might have a "Document" node type that we'd like to go into files/documents/YYYY-MM/filename.pdf and a "Photo" node type that should go into files/images/category/picture.jpg

#1

Crell - June 15, 2007 - 22:47

Hm. I suppose that would likely involve moving the confirm form to the node type config page. Of course, how then would you just set a single global rule? Or per-node type with a fallback to global if nothing is specified?

#2

webchick - June 16, 2007 - 00:08

Global fallback seems like the best option. yeah.

Something like:

Global upload path:
[ textfield ]

[ node type #1 (collapsed fieldset: no value exists yet) ]

[ node type #2 (expanded fieldset: value exists ]
[ textfield ]

etc.

#3

lewmich - June 27, 2007 - 09:42

YES. This feature would be really worthy. Sollution presented by webchick in #2 looks great.

#4

doc2@drupalfr.org - July 26, 2007 - 16:51

I need this badly too, especially to avoid conflicts with the image and video modules.

Else, what code to put in the module to avoid certain content type?

Just below If (isset($node->files)) ... , I tried to put something like if ($type->image) { } else { upload_path code }. I tried with isset as well, but, see, I'm a newbie and couldn't make it work.

Big thanks in advance! Greetings,
Arsène

#5

davidwhthomas - November 7, 2007 - 22:10

I added this feature to my install of uploadpath.

You can set the upload path for each content type.
If a path is not set, the default uploadpath path will be used.

The files are attached.

To install, you can just overwrite the existing files with the new ones and visit the file upload paths config / settings page

AttachmentSize
uploadpath.tar_.gz 7.75 KB

#6

Crell - November 7, 2007 - 22:12

David, can you roll a proper patch so people can review it? Thanks.

#7

davidwhthomas - November 8, 2007 - 21:46

Here's the patch generated from :

diff -up uploadpath_original.module uploadpath.module > uploadpath.patch

See attached :-)

AttachmentSize
uploadpath.patch 3.46 KB

#8

doc2@drupalfr.org - November 13, 2007 - 12:36

I'll try this soon and let you know! Thanx in advance David!

#9

doc2@drupalfr.org - November 16, 2007 - 11:58
Status:active» needs review

Hey, big thank you! Looks and works great!

Therefore I made an archive of the patched module, containing the patch infos within the module and readme file.

http://arsene.richard.free.fr/ged/uploadpath_20071108-patched.zip

Sorry, no garanties, code needs review! I don't know yet how to make official releases (if ever I were granted to). Therefore the module's version has not been changed.

#10

doc2@drupalfr.org - November 16, 2007 - 12:10

JUST IN CASE: Patch suggestions for per-nodetype uploadpath redirection without default:
http://drupal.org/node/192752

#11

davidwhthomas - November 16, 2007 - 12:46

Thanks, glad to hear it works for you too.
I'm using it myself and it's working perfectly :-)

There's a few notes in the comments that could be taken out of a released version (lines 101 - 103 in .module file)
and I'm considering adding the bugfix ( http://drupal.org/node/153737 ) as an optional config setting that can be toggled from admin, in case people want to switch it off, but it works for me and fixes the bug I had with the token module and dates and allows setting paths for each node type.

Thanks to the original dev as this is a very useful drupal extension!

regards,
DT

#12

doc2@drupalfr.org - November 16, 2007 - 13:39

Support request on uploadpath_20071108_patched module:

I have a "files/videos" folder for my video nodetype. I'd like uploadpath redirections to subfolders according to taxonomy terms.

EX.:
If I want a video:
- tagged with a taxonomy term "AAA" to be uploaded in a files/video/AAA subfolder

and a video:
- tagged with a taxonomy term "BBB" to be uploaded in a files/video/BBB subfolder

... can I use the token patterns to do so, and how?

Thanx for any hint or explanation!

Arsène

#13

davidwhthomas - November 17, 2007 - 02:44

Re: Support request on uploadpath_20071108_patched module

In that case, you would create the pattern:

video/[term]

for the "Video" node / content-type.

you could also set it as :

[type]/[term] or [type]/[cat]

as the default pattern and [type] will be replaced by the 'video' content type name.


[type] selects the node type
[term] selects "Name of top taxonomy term"

or perhaps

[catpath]  "Same as [cat], but including nodes supercategories separated by /"

The available tokens are listed in the 'replacement patterns' fieldset in admin > site configuration > file upload paths

It's useful to add date tokens to order your folders by date.
e.g if a pattern like :

[type]/[yyyy]/[mm]

orders files automatically by creating folder by date.

regards,

DT

#14

SergeyK - January 17, 2008 - 15:26

David, thank you for the great job! Your module works fine on my almost clear D5 installation and solves token module date() error message (http://drupal.org/node/153737). But now I am thinking of another feature. Is it possible to integrate "clean" node title produced by Pathauto module into Uploadpath path rendering? Imagine, you have a story titled "Lorem, ipsum". For this node Pathauto (when tuned properly) will generate a path like www.example.com/lorem-ipsum (notice, comma is eliminated, space is replaced by hyphen separator char). As for Uploadpath, used with [title] pattern, it will generate path like www.example.com/lorem,_ipsum. What am I looking for is a common way for naming stories' aliases and paths of images attached to that stories, so that image.jpg will sit in www.example.com/lorem-ipsum, not lorem,_ipsum. Is it possible to implement a hook or fetch processed title data from Pathauto for Uploadpath?

#15

davidwhthomas - February 3, 2008 - 21:40

The latest patch is available in this related thread:

http://drupal.org/node/192752#comment-657282

DT

#16

davidwhthomas - September 8, 2008 - 08:34
Status:needs review» closed

committed

 
 

Drupal is a registered trademark of Dries Buytaert.