-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Netlify cms with GatsbyJs image upload path problems #843
Comments
Currently we do not support relative paths for media, although we would be glad to accept a patch if you are willing! There is more information at #325. |
@thomasheimstad Just wondering, did you try setting the I'm not sure exactly what your site looks like when it is actually built. |
@tech4him1 Hi, thanks for answering. Yes, I did try to set it to "posts/img". Also to "./img" and "/img" but it keeps failing. I don't really need a relative folder, I just need to be able to set the same folder for image uploads as my image folder. With the following folder structure, how do I config my config.yml for the Netlify cms:
If it helps, you may find the github repo here: |
@thomasheimstad What does the directory structure look like when you build the site (I think the |
@tech4him1 Public folder looks as such:
|
@thomasheimstad Try setting the |
@tech4him1 Tried before, tried again to no avail. It creates the post in the right folder with this frontmatter:
|
Are you testing it with |
Both, and neither are working. The error from the terminal when trying to do a gatsby build:
So whenever the frontmatter of the post = Uploading via Netlify CMS always returns a "/" in front of the suggested folder, and gatsby doesn't comply. Here's the full query, if it helps:
|
It looks like you would either have to have relative path support in the CMS (#325 (comment)), or modify your build so that it doesn't try to modify the paths. There is also a Gatsby starter template here: https://github.com/AustinGreen/gatsby-starter-netlify-cms. I don't know if you would be able to use the config from it to help you set up your site (I'm no Gatsby expert 😄). |
@erquhart Since you've been working on the media library, do you know if there is any better way to set this up? |
@tech4him1 Thanks so far, Caleb! I tried copying the starter, but again to no avail. Let's await erquhart's response, we might get lucky! |
When your frontmatter has |
It doesn't even build when the query returns nothing for the
If I manually change to img/testimg.jpg, and check Google Developer, it shows the full static path when I import images with When I import images using the GraphQL-query, it shows only a relative path: So the frontmatter path must, apparently, be relative to the position of the markdown-file, and the image must reference the original image path?
Thumbnail at |
Alright, so good news: I figured it out; bad news: you can't use Gatsby plugins on static resources. First, the CMS needs to exist entirely in the static folder. See the Gatsby starter and cms docs for reference.
At this point your
media_folder: static/img
public_folder: img Next, treat image fields as simple strings, since they won't be converted to Sharp nodes by Gatsby any longer - so your query BlogPostBySlug($slug: String!) {
markdownRemark(
fields: { slug: { eq: $slug } }
) {
html
timeToRead
excerpt
frontmatter {
title
date
category
concertDate
location
startTime
tags
thumbnail
}
fields {
slug
}
}
} If you really want the image processing, here's a third way that should work:
Now you can upload images to the media library, but you'll enter the text path to use an image, rather than inserting the image from the library. You could probably also use a custom preview to show the final Gatsby image in the preview pane, not certain what hooks Gatsby provides for that. Hope this helps! |
Update: I submitted a PR to get the gatsby starter on point for media library usage (and it was merged), so you can reference that as a pattern. Going to close this, but join us on Gitter if you need any more help getting off the ground! |
@erquhart Thanks a lot for your help! Personally I have no problems doing this manually (uploading, then adding the image manually as a string), but it's still pretty bad UI-design. Is there any way of changing the frontmatter field programatically, for instance with gatsby-transformer-remark? Two ideas, either checking if the field starts with "/" and then changing to "./", or to programatically create a new hidden frontmatterfield which copies the returned string of the image widget, and then prepends the necessary ".". It still feels hacky, though, and I'm starting to think there must be a way to access the way netlify-cms handles the image paths (such as not prepending the "/"). |
@thomasheimstad folks are working toward a proper solution to the Gatsby/Netlify CMS image issue in #325, have a look there. |
having the same issue in 2020 |
Hi @stephaniedavidson, the CMS no longer prefixes a I would suggest opening a new issue based on the issue template and describe a reproduction scenario |
Hi!
Kudos on this excellent project, I'm having so much fun trying this out!
However I'm experiencing some slight difficulty getting the upload image function working, and it seems to be related to the image path of the config.yml settings.
If I manually upload images to the src/posts/img folder, and name the image manually in the frontmatter as such:
it works! Notice the ./img, I'm finding the images in the folder "img" which is in the same folder as my markdown files.
When I upload an image from the Netlify CMS admin UI, it receives the following path:
Notice the relative "/img path.
My GraphQL query fails miserably when trying to find this image:
I've exhausted testing different paths and solutions in config.yml, and I can't seem to override the behaviour of public_folder, adding a "/" before the path name. If I do:
it just adds "/./img", and the query continues to fail.
Here are the rest of my settings, and my GraphQL query:
config settings:
gatsby-config:
file structure:
GraphQL-query:
Truly hope some of you may spot my rookie-mistake!
Thanks in advance.
The text was updated successfully, but these errors were encountered: