All my Drupal Commerce files are being saved in the same directory on the server.

I have a Commerce product variation of type of album. Each album contains multiple Commerce files (mp3’s, m4a’s). I want each album to have its files saved in a different directory depending on artist name and album name.

For example: commerce_mp3s/artist_name/album_name/album_files*

I tried looking in the DB where these Commerce files are referenced, table name being field_data_commerce_file, but file paths are not used there.

The worst case scenario would be to change the file path of the content type every time I add a new album, but that’s not a solution. This must be a common scenario.

How can I accomplish this?


You need to use the Token with File (Field) Paths and Pathauto modules.

Note: File (Field) Paths extends the token module by adding Node tokens, without this module, you will not be able to use the node fields as tokens.

Then edit your file field.

enter image description here

We then use Pathauto to fix names with spaces. Ex: If the album name is "Hello World" the path/folder name will change to /hello-world/

enter image description here

  • 1
    Merci for the FFP-module tip! I would add some relevant quotes (what it can be used for) from its project page to this answer also ... Unless of course you want people to be curious and go check the module's project page ... – Pierre.Vriens Jul 8 '16 at 7:18
  • @Pierre.Vriens thanks for the feedback, updated the answer. – No Sssweat Jul 8 '16 at 7:29
  • Thank you, this is great of course but Nodes are not showing up in the Available Tokens window for the Product Variation Type field page for the file field. Maybe because Product Variation is not a node? – TopTomato Jul 8 '16 at 19:41
  • though it does show up in other places like Pathauto URL aliases pattern page – TopTomato Jul 8 '16 at 19:43
  • 1
    For a product variation, the node category definitely does not show in available tokens however 'products' does. I was able to use that instead. thanks for the help! – TopTomato Jul 8 '16 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.