question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Beta Bug: media_folder_relative also setting relative path when uploading images

See original GitHub issue

Describe the bug I’m referring to a Gatsby issue Issue 4753, where you announced relative image paths in the beta. This works great for loading files from the static folder that already exist, but uploading a new file via the admin also saves them as relative paths to the .md file, making it impossible to find it later when loading (basically ignoring the media_folder setting).

To Reproduce

  1. Install the Beta “^2.9.8-beta.3”
  2. Set the config media_folder_relative: true media_folder: "static/uploads"
  3. Upload an image via the netlify admin area
  4. Check the .md file image path

Expected behavior Uploads should be saved as image: /uploads/logo.png, but instead they’re saved as …/…/…/uploads/logo (number of directory changes depending on where the page lives).

Applicable Versions:

  • Netlify CMS version: “^2.9.8-beta.3”
  • Git provider: Gitlab
  • OS: MacOs

CMS configuration ` backend: name: gitlab repo: ******** auth_type: implicit # Required for implicit grant app_id: ********* api_root: ******** base_url: ******** auth_endpoint: oauth/authorize media_folder_relative: true media_folder: “static/uploads” public_folder: “/uploads” collections:

  • name: navbar label: Navbar folder: src/markdown/widgets/navbar create: true fields:
    • {label: “Template Key”, name: “templateKey”, widget: “hidden”, default: “navbar-widget”}
    • {label: “Title”, name: “title”, widget: “string”, hint: “Please choose a unique name for the Navbar. The grey background will just be visible here, the regular navbar will be transparent”}
    • {label: Logo, name: logo, widget: object, fields: [{label: Image, name: image, widget: image}, {label: “Image Alt”, name: imageAlt, widget: image}, {label: Path, name: path, widget: string}, {label: Alt Text, name: altText, widget: string}]}
    • {label: Tabs, name: tabs, widget: list, fields: [{label: Label, name: label, widget: string}, {label: Path, name: path, widget: string}, {label: Offset, name: offset, widget: string}]}
    • {label: “Call to Action”, name: cta, widget: object, fields: [{label: Text, name: text, widget: string}, {label: Path, name: path, widget: string}]} `

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
erezrokahcommented, Oct 22, 2019

Sorry to jump in late into this discussion, but there might be another solution. I’m using this Gatsby plugin to make sure the CMS paths play nice with Gatsby. I can confirm I’m getting optimized Gatsby images just by adding the plugin, which I believe was the point of the original issue in the Gatsby repo.

1reaction
s0commented, Sep 26, 2019

Ah yes, I forgot that previews don’t work for this, and weren’t fixed in my original PR, I mention it at the end of the description here: https://github.com/netlify/netlify-cms/pull/2394.

Rather than calculate the published path for an image, I feel it would make more sense to embed the image directly from the backend (e.g. GitHub) like is done with the gallery picker (IIRC), rather than try and resolve the published location for the image.

This is slightly more robust, and allows for e.g. staging environments (master publishes to staging and is checked there before publishing a blog live), where the image may not yet be publicly accessible even if it’s in git.

Read more comments on GitHub >

github_iconTop Results From Across the Web

img tag not working with relative path in src - Stack Overflow
Inspect the img element, right-click on the src and Open image in new tab to see the url that it's trying to get....
Read more >
CSS background-images doesn't load with relative path inside ...
Issue 270059: CSS background-images doesn't load with relative path ... Append inline CSS styling the element with a background-image using a relative path....
Read more >
Support use of relative path for image file pathname in ...
The step type already supports relative paths by using the search directories, so if the image file is in the same directory as...
Read more >
Bug: Maps saved with relative paths can have broken data ...
Technical Article Details : Bug: Maps saved with relative paths can have broken data paths when reopened from Windows Explorer or a Windows...
Read more >
Externally referenced files (Xrefs) set to Relative path are ...
Issue : Externally referenced files (Xrefs), such as PDF files, raster images, or drawings, that are set to use a Relative path are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found