It's very weird but sometimes when using [node:nid] in the file path it doesn't work, even though the settings are exactly the same. If the path is set to "test/[node: nid]", a folder named test will be created in the directory but the file uploaded was just in sites/default/files/.

But sometimes when I add another file filed and do the same setting it works. This really baffles me. Did I miss anything? Any feedback would be highly appreciated.

Comments

aboodred1’s picture

I guess that this module doesn't support token [node:nid]

Deciphered’s picture

Status: Active » Postponed (maintainer needs more info)

File (Field) Paths does support Node tokens, it was created specifically for Node tokens.

It's possible that it's a workflow issue, because Node tokens can't be processed until you save the Node, so if you're seeing the issue prior to saving the Node it should be remedied after you save the Node.

Please confirm whether this is the case.

MO-2’s picture

Category: support » bug
Status: Postponed (maintainer needs more info) » Active

I think the bug, or confusing part, is that the [node:nid] token doesn't appear in the list of available tokens above the FILE (FIELD) PATH SETTINGS expanding field settings group because it is for the help text above. Try the tokens replacement patterns section below.

MO-2’s picture

Category: bug » support
Status: Active » Fixed

marking as fixed.

Status: Fixed » Closed (fixed)

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

broon’s picture

Title: [node: nid] working occasionally » [node:nid] works only on first file in multi-value file field
Status: Closed (fixed) » Active

A client wants to organize attached files as being saved in /files/node/[node:nid]/filename.ext
Since Drupal core does not allow Node tokens, I used this module and just experienced the same bug. If I edit an existing node, say /node/1, the first file I upload ends up in
/files/node/1/file1.pdf
(which is as I expected). However, all files I upload next before saving end up in
/files/node/ajax/file2.pdf.
So I guess, this is somehow messed up during the Ajax upload of the first file.

If I upload the files one-by-one and save the node in between, it works because the first file is always in the correct folder.

Deciphered’s picture

I have honestly never seen that behaviour before, and I can't even see how that would be happening as that would require a node object to have 'ajax' against the nid, which points to bigger problems.

If you're up to debugging, sticking a DPM before the call to token_replace() to see what the node object contains would be a good place to start.

If you're not up for debugging, I would happily do it on your behalf if you could give me 100% guaranteed working reproduction steps so I can see the issue locally, or if you could give me access to the site where it's happening as well as access to the filesystem so I could debug.

broon’s picture

Status: Active » Closed (works as designed)

I have found the source of irritation. First, everything seems to work fine now.
Second, here is what happens from my perspective. Creating a new article (node/add) or edit an existing one (node/1/edit) both works. But while on the node add/edit form, the files are uploaded to diverse locations.

For example, upon creating node 1, the first file is uploaded to /files/node/add/file1.ext (confirmed via SSH login). As soon as I hit save however, the file is moved to /files/node/1/file1.ext which is where I wanted to be. Since node id is not yet known before I hit safe, this is absolutely ok.
The irritation started when my client added more files while using the Insert module.
Visiting /node/1/edit, the first new uploaded file went to /files/node/1/file2.ext (confirmed), while the second new file was saved at /files/node/ajax/file3.ext. The files are all moved correctly when finally hitting "Save", but my client used the Insert button to insert an image or document link in body text and noticed the "wrong" file paths.

However, this module does take care of that when saving the node (it actually replaces the /node/ajax/ links with the non-temporary paths), the description already lists the question "Why are my files uploaded to 'files/[nid]' instead of 'files/1'?", it might need an addition about the other possible temporary locations (add/ajax).