We help IT Professionals succeed at work.
Get Started

Why does this image now show up despite some flawless code?

Bruce Gust
Bruce Gust asked
Last Modified: 2020-02-20
Here's how the resource looks in Compass...

So, it's getting stored in the database correctly. Here's what the React code looks like:

import React, { Component } from 'react';

import Image from '../../../components/Image/Image';
import './SinglePost.css';

class SinglePost extends Component {
  state = {
    title: '',
    author: '',
    date: '',
    image: '',
    content: ''

  componentDidMount() {
    const postId = this.props.match.params.postId;
	if(postId) {
		fetch('http://localhost:8080/feed/post/' + postId, {
			headers: {
			Authorization: 'Bearer ' + this.props.token
		  .then(res => {
			if (res.status !== 200) {
			  throw new Error('Failed to fetch status');
			return res.json();
		  .then(resData => {
			  title: resData.post.title,
			  author: resData.post.creator.name,
			  image: 'http://localhost:8080/' + resData.post.imageUrl,
			  date: new Date(resData.post.createdAt).toLocaleDateString('en-US'),
			  content: resData.post.content
		  .catch(err => {

  render() {
    return (
      <section className="single-post">
          Created by {this.state.author} on {this.state.date}
        <div className="single-post__image">
          <Image contain imageUrl={this.state.image} />

export default SinglePost;

Open in new window

Here's what it looks like when you inspect that big, honking blank where the image should be displayed:

[code]<div class="image" style="background-image: url(&quot;http://localhost:8080/imagesmuscular.PNG&quot;); background-size: contain; background-position: center center;"></div>[code]

Why does the image get rendered as "imagesmuscular.PNG" as opposed to "image/muscular.PNG?"

Any ideas?
Watch Question
Fractional CTO
Distinguished Expert 2020
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE