I am not completely sure if this is a bug in the Filefield Paths module or elsewhere, but I am experiencing some strange behavior. I am using the filefield paths module to control the upload directory for a filefield cck field. The pattern I am using to set the file path is something like:

pubs/[token1]/[token2]

so if I upload "test.pdf" it should be put in files/pubs/[token1]/[token2]/test.pdf, where the tokens are filled in from other cck fields in the node. This works, in that the file is uploaded to the intended directory.

However, after creating the node, the link to the file is incorrect. It points to "files/pubs/test.pdf" instead of the directory where the file is actually sitting. This link is fixed if I (a) edit and then re-save the node or (b) run a retroactive update.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

loze’s picture

I am having the same issue. (i think)
http://drupal.org/node/641252#comment-2300248

Deciphered’s picture

Status: Active » Fixed

As FileField Paths uses node tokens which can't be populated until the file is saved, the path isn't processed until you save.
Links to the old path will also be processed upon save, however this is improved somewhat in the current development build.

Cheers,
Deciphered.

Status: Fixed » Closed (fixed)

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

Agileware’s picture

Title: Strange behavior with links to uploaded files » Node links to original file path after creation until the node is saved again
Version: 6.x-1.3 » 6.x-1.x-dev
Category: support » bug
Status: Closed (fixed) » Active

This issue was hard to track down due to a few issues with bad titles so
I'm fixing it up a little as it might be reasonably common.
Hopefully this title is a little clearer.

As mentioned in #641252: Strange behavior with paths on Node creation.
this issue is related to this modules weight.

If the weight of this module is changed to be after whichever module is interfering
the problem goes away.

In my case the module was uc_node_checkout, which has its weight set to 100.
To fix it I set the weight of this module to 101.

Other people have fixed it by setting the weight to 20.
It depends on what other modules you have.

So a fix for this module would be either:
1. Set the weight of this module above everything else (modules installed after this one would be another issue)
2. Make a note in the documentation and on the project page about this weight issue

Sera’s picture

Version: 6.x-1.x-dev » 6.x-1.4

The Bug is nevertheless still active for 6.x-1.4.
But I tried the recommended solution: "I just changed the weight of filefield_paths in the system table of the database from '0' to '20'".
At a very rough test it fixed my issue, but I will test it more intensively the next week.

update: Sadly the error still appears. It's hard to test as sometimes the upload is ok, sometimes not.

arthursk’s picture

Further confirming this issue.

FileField Path does not pass the NEW filename and/or path until AFTER the node has been created, then edited and resaved

Changing the weight to 20 appears to have solved the problem, is this a safe fix?

Sera’s picture

No, sadly the issue is still active. Probably the path does appear to be correctly more often, but the filename is still not always correct. :(

Yesterday my filepath was again /system/files/ instead of /system/files/[token]/[token]/
Thus changing the weight is not our patch :(

Agileware’s picture

Have you installed new modules that have a higher weight value than what you originally changed your filefield paths weight to?

I have been running with this weighting fix for 3 months with no issue.

alison’s picture

I have had this problem and it's driving me crazy!! But I will try the weight fix.

Do y'all think this issue and http://drupal.org/node/844368 are related/the same?

Also, do you think this issue and the issue I linked to (844368) might be related to this other temp paths issue? http://drupal.org/node/650664

(subscribing...)

hefox’s picture

Status: Active » Needs review
FileSize
735 bytes

Having similair issues

In my case, as far as I can telll, the _field_file_cache is never cleared, which isn't a problem.. till something calls node_load during the same page (static cache, only persists for the current page).

So in my case
1) field_file_load is called before filefile_paths, _field_file_cache the result
2) filefield_paths does it work

then if ...
3) Node load is called for that node during the same page load
4) content_load load the files
5) filefield_field_load grabs the cached, incorrect filepath
6) content_load caches the result (it drupal caches, ie cache_set, all field information, so until that is cleared, ie via node save, every node_load returns that cache no matter the page load).

... And thus, BAM.

In my case it was nodelrelationships node add popup that was calling node_load to get the title I suspect.

The weight trick likely worked due to the situation being the other modules calling node_load, then filefiled clears the cache.

Wouldn't work in all cases though, like my case cause the node_load is called in a final submit handler for noderelationship.

But simply clearing the _field_file_cache should address it :).

nplus1’s picture

Priority: Major » Normal

i have the same issue but with the file name not the path: http://drupal.org/node/844368 you need to save it twice to get the right name in your page. the 3 lines above fixed my problem! thanks!

alison’s picture

Priority: Normal » Major

I just tried the patch at #10 -- brilliant! Totally fixed the problem(s) I was experiencing (see #9)!! Thank you, hefox!!

(Just so y'all know, I applied the patch manually because the site in question is on, erm, "special" hosting that does not include command-line access -- as such, I can not speak to whether or not the patch can be applied without problems etc..)

ShadowMonster’s picture

Priority: Normal » Major

subscribing

jejk’s picture

subscribing

Magnus’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
Component: Miscellaneous » Code
Status: Needs review » Reviewed & tested by the community

This took the whole evening to figure out. I thought I made some mistake with the Tokens in my paths until I finally found this thread. The patch in #10 works great. Thanks a lot!

Deciphered’s picture

Status: Reviewed & tested by the community » Fixed

Commited to DRUPAL-6--1: http://drupal.org/cvs?commit=434406

Status: Fixed » Closed (fixed)

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

joshuajabbour’s picture

I know this is fixed in dev, but I need a patch usable by drush_make until there's a new stable release.

joshuajabbour’s picture

one more try. not sure why the second of these seemingly identical patches applies, but...

Todd Zebert’s picture

Using 6.x-1.x-dev (2011-Feb-24) and module weight 100, still getting problem. Although I'm uncertain now if Saving first is still required, or just a good idea?

TravisCarden’s picture

Status: Closed (fixed) » Reviewed & tested by the community

I still have this problem using 6.x-1.4. The code supplied in the patches above is absent from the module. Perhaps we had a regression? The patch in #19 solves the problem. (Thanks joshuajabbour.) Can we get it committed again?

jthomasbailey’s picture

Newest Dev seems to have it.

aitala’s picture

A quick question - if I apply patch to the current release version of FileField and resave every affected node through View Bulk Operations, will that fix the 'file not found' issue?

Thanks,

Eric

kbk’s picture

Status: Reviewed & tested by the community » Closed (fixed)

2 years since a stable D6 release. Doing so may head off spurious issues on old topics like this. It would have also spared me the last hour of googling.

roball’s picture

Version: 6.x-1.x-dev » 6.x-1.4
Assigned: Unassigned » Deciphered

The fix is now officially available in version 6.x-1.5.