I noticed that if you upload a file with a name that already exists, the old file is not rewritten but a duplicate image entry is added to the node without warning. To reduce the likelihood of this happening and yet keep the folder structure simple I wanted to group the images into folder by Node ID. This is not possible with the current release version.

I request that the full range of tokens be made available for use with the Image Path.

In the mean time I've hacked imagefield.module to use the node token type instead of user.

Comments

ajayg’s picture

Could you please share your hack to use node type token?

jmstacey’s picture

Status: Active » Needs review
StatusFileSize
new2.13 KB

I made a few adjustments and created a patch which you will find attached. It enables all token replacement possibilities.

I haven't tested or looked at all of the tokens that this makes avaialable to make sure that they are applicable but it is working properly for my needs (the [nid] token).

whisk’s picture

StatusFileSize
new1.97 KB

Uh... Not worked for me. I believe, there is no 'all' mode for token_replace().
Instead, I've created a quick and dirty patch just for node tokens.
[nid] works perfectly, but keep in mind that it's not possible to use node tokens before node gets created. So, when creating a node, you should not upload images, just specify only one image ("browse" button) and hit Submit. After node is created, there is no restrictions.

jmstacey’s picture

What version of token and imagefield are you using? It seems to be valid for me on 5.x-1.11 patched against imagefield 5.x-2.1

whisk’s picture

Token: version = "5.x-1.11"
Imagefield: version = "5.x-2.1"

dagmar’s picture

StatusFileSize
new3.04 KB

I have created another patch. It uses both, node and user token replacement patterns.
Also it uses collapsible fieldsets like pathauto or workflows ng.

jmstacey’s picture

@whisk, you're completely correct, it does not work (just retested). That was very sloppy of me and I apologize. The 'all' does end up showing all available tokens on my end however the actual substitution does not take place. The patch from dogmar works correctly and is more elegantly implemented.

Using [nid] appears to work correctly after performing this fix: http://drupal.org/node/207768

jajathejazzcat’s picture

FYI, I have used [path-arg-2] token to replicate nid. Even if you have an alias url, the system path will be used (e.g. example.com/node/1/edit). Of course there is still same limitation that you can only upload images after a node is created, as whisk said in comment #3, but it might be better than hacking the module.

whisk’s picture

Yes. The only solution is to fix the module so all image attachments would be processed after actual node creation, like in upload module (AFAIR).

roderik’s picture

StatusFileSize
new3.43 KB

Attachments _are_ actually processed after node creation.
Only the link to the preview image is broken; after actually saving the node after preview, everything is OK. (At least after you've applied http://drupal.org/node/207768#comment-1079996; I have not tried without.)

During the preview phase, the image files are actually still called something funny like 'files/tmp/tmp_IGxOnZ'... the menu system just creates temporary 'normal' aliases for them. Apparently those aliases cannot have double slashes in them, so I modified dagmar's patch (#6) a little. Things work for me, now.

N.B.: there is a 'directory creation' statement in this preview phase, which I think is unnecessary, but I didn't dare to delete it :) So I just put a comment behind this like "is this necessary?".
Still 'code needs review'.

quicksketch’s picture

Status: Needs review » Closed (won't fix)

New features are not being added to the Drupal 5 version. In Drupal 6 try the FileField Paths module.