4

I have a local asset folder defined with name 'Local storage' file system path ../public/cms/images/, and URL /cms/images/.

I create an Assets field named 'Hero image', not restricted to a single folder, with source 'Local storage', and default upload location 'Local storage' with path heroes/{slug}/.

I'd expect uploads for Hero image to land in the /public/cms/images/heroes/{slug} folder. When I do upload an asset, this folder is created, yet the asset lands in the root /public/cms/images folder.

Why might this be?

1
  • Try using absolute paths/URLs and see if that works. You probably just have a relative path setup incorrectly somewhere.
    – Brad Bell
    Nov 17, 2014 at 17:30

1 Answer 1

5

This answer really belongs to Brad, as he mentioned it to me. But he doesn't really need the points, does he ;)

What you want in that slot is {owner.slug}, and then the proper sub-path will ensue.

The explanation is deep in the doc page at: http://buildwithcraft.com/docs/assets-fields

To wit,

"Note that if you are creating the Assets field within a Matrix field, the source element is going to be the actual Matrix block, not the element that the Matrix field is being created on. So if your Matrix field is attached to an entry, and you want to output the entry ID in your dynamic subfolder path, you would type {owner.id} not just {id}."

9
  • You get the rep fair and square. :) Didn't even think it might be in a Matrix field.
    – Brad Bell
    Nov 18, 2014 at 3:23
  • I did rather make the assumption, didn't I...but the reason is that the only place {slug} is mentioned in this fashion is in the form for Matrix images. Really, it should say {owner.slug} there to be correct, shouldn't it? Nov 18, 2014 at 7:41
  • That's a good point for matrix fields. However I'm still having the same problem for non-matrix fields after making the file system path absolute.
    – Alex H
    Nov 18, 2014 at 14:12
  • 1
    The correct subfolder is created in the filesystem, but as the root 'Local storage' location is highlighted when I open the 'Add an asset' dialog it adds it there. If I highlight the correct folder manually I get an error where there is a double directory separator slash: 'Error uploading the file: The folder "/home/apps/test/public/cms/images/heroes//history/" does not exist.' I've double checked and there don't seem to be any trailing slashes on the paths I've set.
    – Alex H
    Nov 18, 2014 at 14:20
  • Ah, I understand now that this default upload location will only be used if the asset is dragged onto the field, or the 'Restrict uploads to a single folder?' is checked. I'm still getting the double slash error though.
    – Alex H
    Nov 18, 2014 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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