This is my setup:
Content type Media contains next fields:
"Audio"
filed with upload directory to: media/books
(Audio field is provided by Audiofiled module)"Book"
field term referenceThe "Book"
vocabulary contains plus one text field called "Folder"
that contains folder name for each book.
I want to use that field value to append it to the file path for uploading the audio file in that subfolder.
It uploads the file in the temporary folder but doesn't to the proper one, e.g. if for the "Book"
term "Book 1"
, "Folder"
field value is "book_1"
, I want the audio files to be uploaded in the "media/books/book_1"
folder.
I am using File (Field) Path module and I am not sure how to configure it properly.
In my "Audio"
field I set the File path setting to
"media/books/[node:field-book:field-folder]"
But nothing is happening. Maybe I don't use the right token or something else is the problem?
You don't need "folder" field in your vocabulary. Problem here is that Drupal's core file module doesn't support entity based tokens.
For this you need to install few modules. You need entity tokens module (it comes with entity API module) and you already have file paths module.
Now you should have what you want.
When you select file for upload and click upload button Drupal can't take path from reference term because value you selected there isn't parsed yet via Drupal core. Even when you try to save content without previous clicking on upload button Drupal core will first try to upload selected file but it will not know destination.
File (Field) Paths module temporary upload file on default folder destination (because of that you need to set the path to that directory without tokens - in your case /media/books). Once you save the node and Drupal is provided with the Node tokens values the file is moved on desired destination (in your case /media/books/token_values).
Addition:
In line:
media/books/[node:field-book]
token value is taken from book field from your media type which is defined by your vocabulary. Rename token values means to rename your taxonomy terms into names related to your books. If you already have folders on server that you can't rename then it is good choice to have another field in your vocabulary.
File (Field) Path in audio field in your media content type should be:
media/books/[node:field-book:field-folder]
So if you set your folder values book_1 for Book 1, book_2 for Book 2, etc...
When you select "Book 1" during upload you should be able to upload files in
media/books/book_1
or
media/books/book_2
Note: Drupal will not delete created folders if/when you change values of tokens.
Hope this helps.