Wrong file path copied from media page in Netlify CMS admin

I have a Jekyll + Netlify CMS site, which is set up according to the docs.

I encountered a problem with copying uploaded file paths from media library page in admin. Basically, the “Copy path” button gives me a path like this assets/uploads/file.txt and I believe it should instead give me /assets/uploads/file.txt.

Of course I can prepend a / when using these links, but this is somewhat problematic for non-developer content editors. For example, if the editor uploaded a PDF file they later need to refer from a blog post, the rendered page will have a broken link like this: https://example.com/2021/09/09/blog-post/assets/uploads/file.pdf, because the browser thinks the file is relative to current page, not the root.

My admin/config.yml looks like this:

backend:
  name: git-gateway
  branch: main
media_folder: 'assets/uploads'
collections:
  ...

I wonder if this is an error or a designed behavior, and how I might fix the problem. Maybe I need to change my admin/config.yml?

Or maybe I can somehow force the “Copy URL” button to appear instead of the “Copy path” button. Looking through the Netlify CMS source code, such button exists and should allow copying absolute URLs but I wasn’t able to figure out the circumstances under which it would appear.

While I’m not sure about that, I believe you could use a different collection for each post and the files could then be relative to that post. In such a setup, the URLs would probably be correct.

Here’s a thread from when I wasn’t working here:

That could possibly help you figure out how you could do what I’m saying.

Try setting the public_folder property as well.

media_folder: 'assets/uploads/'
public_folder: '/assets/uploads/'

The media folder points to the folder in your repo . The public folder sets the right path for publishing the content.

Hi @tomrutgers. Thanks for the suggestion. I already tried that and it doesn’t help in this case. The path I copy still lacks the leading / character and on deeply nested pages (such as blog posts) browser goes one directory up, resulting in a broken link.

I don’t think this has to do much with Jekyll blog permalinks specifically. If I had other page types placed deeper than 1 sub-directory, I believe this problem would surface there as well.

This has more to do with how browsers work with relative paths so that’s why I think the solution should be somewhere on the media page itself. It should allow copying either a full URL or a relative path with a leading /.

Hi there! Thanks for your interest in Netlify CMS. Looks like you posted your question a little while ago, but that you haven’t received a solution yet. Here’s where you might get more help:

netlifycms.org - the site houses our extensive documentation that likely contains helpful information to get you back on track.

netlify cms slack - join our friendly slack channel and chat with other cms pros to get the help you need.

GitHub Issues - think you’ve found a bug, or would like to make a feature request? Make your voice heard here. Netlify CMS is open source - PRs and other contributions are also welcome!

Stack Overflow Check StackOverflow for questions tagged “Netlify CMS” if you don’t get an answer in the Slack or the GH issues. StackOverflow reaches a worldwide audience of knowledgeable people.

Your question will be left open here for anyone to comment - but we encourage you to check out the above resources if you are still looking for a solution!