Is there any way to make the hyperlink to the file be correct as soon as the file is uploaded?

I'm moving my files into a directory that's specific to the taxonomy term that the page is tagged with. So I'm using [term-raw]. I'd love for the links to the files to be correct as soon as they're uploaded, so that the user could just right-click on the icon representing the file, copy the link, and paste it into the body. Is there any way to do this? Maybe I'm just missing it.

Right now the link to the file is missing the [term-raw] until the node is saved. This forces the user to upload the file, save the node, then edit again and grab the link they need.

Comments

deciphered’s picture

Status: Active » Fixed

No,

Due to the way that Drupal works, you can't have 100% of the Node tokens available until the node has been created (specifically NID, but there are others). In your very own example, if you changed the Taxonomy Term after uploading the file your path would be wrong.

There is code in FileField Paths that will search through the Node Body and any other CCK textfields to fix incorrect paths, so there is no reason why you can't do what you'd like already :)

Cheers,
Deciphered.

attheshow’s picture

Status: Fixed » Active

Sorry, I'm not sure from the description above what I should do. It sounds like you're saying it's possible, but you didn't suggest a course of action.

deciphered’s picture

Status: Active » Fixed

@attheshow

What I'm saying is that if you upload a file to a node, copy the link to the file and paste it into the body, while the URL will be wrong at the point of pasting it (http://yoursite.com/sites/default/files/file.ext), when you save the Node, FileField Paths will move the file, then search through the Nodes body field and do a find and replace on the old path changing it to the new path (http://yoursite.com/sites/default/files/new-path/new-name.ext).

So you don't need to do anything out of the ordinary, just do the approach you suggested and it will just work.

Cheers,
Deciphered.

attheshow’s picture

Wow, I had no idea that was in the code where it's searching through the body content to see if it needs to make adjustment to links. That looks like it works splendidly.

...unless you upload a second file that has the exact same name as the first file that was moved. Some of my editors have done that in the past, so I just thought I'd check to see what happens. Here's what just happened for me:

  1. upload file named "as501_dell_monitor.pdf" to page, assign taxonomy term "information-technology" and add hyperlink (A) to body, save the page
  2. hyperlink A in page is initially correct and points to /sites/.../files/information-technology/as501_dell_monitor.pdf
  3. edit page again and upload a second file with the same name "as501_dell_monitor.pdf", add a new hyperlink (B) to the body that points to this new file, save the page
  4. file A is still located on the server at /files/information-technology/as501_dell_monitor.pdf and file B is located on the server at /files/information-technology/as501_dell_monitor_0.pdf
  5. hyperlink A is incorrect and points to /sites/.../files/information-technology/information-technology/as501_dell_monitor.pdf
  6. hyperlink B should be pointing to /files/information-technology/as501_dell_monitor_0.pdf, but actually points to /sites/.../files/information-technology/as501_dell_monitor.pdf (which is actually file A).

In that situation, it looks like the behavior is incorrect. Just thought I'd point this out since I was examining the process. I'd like to mark this as a bug report at this point, but am hesitant to do so for fear of upsetting you.

Status: Fixed » Closed (fixed)

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

canzi’s picture

Im having the same issue mentioned above

i.e. ...unless you upload a second file that has the exact same name as the first

if an update of a file is performed = delete -> upload modified file ( same name ) -> save
then all existing links have there "File path:" added again

i.e.
/dpal_redeemer/sites/default/files/test/23202_695109497_4148_n.jpg
gets changed to
/dpal_redeemer/sites/default/files/test/test/23202_695109497_4148_n.jpg

appreciate your help
Steve

canzi’s picture

Category: support » bug
Status: Closed (fixed) » Active
deciphered’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

No longer supporting Drupal 6 issues for this module.