Folder Collections Media and Public Folder not working as intended

Hello,

I am trying to organize my posts in month/year folders while keeping my photos in a single folder instead. Mainly because I am using Netlify Large Media to track all of my media in that destination.

Based on the docs it says if I use this setup.

collections:
  - name: "news"
    label: "News"
    label_singular: "Article"
    folder: "content/news"
    create: true
    slug: "{{slug}}"
    path: "{{year}}/{{month}}/{{slug}}/post"
    media_folder: ''
    public_folder: ''

My images would store in the same folder as my post.

image

But if I remove the relative media and public folders and modify my path.

collections:
  - name: "news"
    label: "News"
    label_singular: "Article"
    folder: "content/news"
    create: true
    slug: "{{slug}}"
    path: "{{year}}/{{month}}/{{slug}}"

Then my images should be sent to my specified folder in my global settings

media_folder: static/img
public_folder: /img

But it does not behave this way. By using path in my blog setup, my images are saved relative to my post and not in my global image folder. :thinking:

I am not really sure what I am missing here. I am still testing other variations here in case I can figure it out. By removing path and only using slug I no longer see my posts in my CMS preview. Any thoughts on this?

Following up on this post. I saw this in the docs.

So no matter what I do my images will be saved relative to my post like in this configuration?

collections:
  - name: "news"
    label: "News"
    label_singular: "Article"
    folder: "content/news"
    create: true
    slug: "{{slug}}"
    path: "{{year}}/{{month}}/{{slug}}"
    media_folder: ''

Instead of using my global settings?

And if I try adding {{media_folder}} to my relative media folder like this.

media_folder: '{{media_folder}}'

I end up having my images saved in a static\img folder relative to my post.

image

Which of course makes sense why it would do that. But then how do I point my media back to my global folder?

Hi @byebyers, you can prefix the media_folder with / and it will be treated as an absolute path:

media_folder: '/{{media_folder}}'

Thank you @erez this really helps a lot. I had to do the same for my public_folder as well.

Leaving the setup to be

media_folder: '/{{media_folder}}'
public_folder: '/{{public_folder}}'
1 Like