Avatar of Bruce Gust
Bruce Gust
Flag for United States of America asked on

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

Here's how the resource looks in Compass...

screenshot
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 => {
			this.setState({
			  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 => {
			console.log(err);
		});
	}
  }

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

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?
Databases

Avatar of undefined
Last Comment
David Favor

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
David Favor

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
slightwv (䄆 Netminder)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bruce Gust

ASKER
Sorry for leaving you hanging for so long, gentlemen!

Thanks for your help!
David Favor

You're welcome!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy