Javascript 如何从MySQL数据库渲染(反应)图像?

Javascript 如何从MySQL数据库渲染(反应)图像?,javascript,mysql,reactjs,Javascript,Mysql,Reactjs,我已经成功地发布了图像文件名并将其取回,但我一直在研究如何在reach ImageGallery组件中渲染它(来源于) this.state={ 伊索彭:错, 图像:[], 档案:“ } } onSubmit=(e)=>{ e、 预防默认值() 风险值数据={ 图像:document.imgAdd.file.value } 日志(“单击提交”,数据); 获取(“/gallery/images”{ 方法:“POST”, 标题:{'Content-Type':'application/json'},

我已经成功地发布了图像文件名并将其取回,但我一直在研究如何在reach ImageGallery组件中渲染它(来源于)

this.state={
伊索彭:错,
图像:[],
档案:“
}
}
onSubmit=(e)=>{
e、 预防默认值()
风险值数据={
图像:document.imgAdd.file.value
}
日志(“单击提交”,数据);
获取(“/gallery/images”{
方法:“POST”,
标题:{'Content-Type':'application/json'},
正文:JSON.stringify(数据)
}).然后(功能(响应){
如果(response.status>=400){
抛出新错误(“来自服务器的错误响应”);
}
返回response.json();
}).then(功能(数据){
控制台日志(数据);
}).catch(函数(err){
console.log(错误)
});
}
componentDidMount(){
let url=“/gallery/images”
获取(url{
方法:“获取”
}).然后(功能(响应){
如果(response.status>=400){
抛出新错误(“来自服务器的错误响应”);
}
返回response.json();
})。然后(图像=>{
this.setState({images:images});
console.log(图像)
}).catch(错误=>{
log('catch it!',err);
})
}
render(){
返回(

我没有收到任何错误消息,但没有看到页面上显示的图像

我不得不删掉一些代码,因此如果有什么不合理的地方,请尽管问。同样,我只是想从数据库中获取图像并在页面上渲染。提前谢谢!!您是否使用get方法获取图像?@KrishnaKamal我正在获取g返回图像地址:“C:\fakepath\IMG_2811.JPG”例如…您希望为这些资产提供服务并用URL更新指向它们,而不是绝对路径:我现在收到此类错误:[对象%20文件]:1 GET 404(未找到)我不得不删掉一些代码,所以如果有什么不合理的地方,请尽管问。同样,我只是想从数据库中获取并在页面上呈现图像。提前谢谢!!您是否使用get方法获取图像?@KrishnaKamal我正在返回图像地址:“C:\fakepath\IMG_2811.JPG”例如…您希望为这些资产提供服务并用urlUpdate指向它们,而不是绝对路径:我现在得到的是这种类型的错误:[object%20File]:1 GET 404(未找到)
      this.state = {
      isOpen: false,
      images: [],
      files: ""
    }
}

onSubmit = (e) => {
  e.preventDefault()
  var data = {
      images: document.imgAdd.file.value
  }
  console.log("Submit was clicked", data);
fetch("/gallery/images", {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: JSON.stringify(data)
}).then(function(response) {
  if (response.status >= 400) {
    throw new Error("Bad response from server");
  }
  return response.json();
}).then(function(data) {
  console.log(data);    

}).catch(function(err) {
  console.log(err)
});
}

componentDidMount() {
  let url = "/gallery/images"
  fetch(url, {
      method: 'GET'
  }).then(function(response) {
      if (response.status >= 400) {
          throw new Error("Bad response from server");
      }
      return response.json();
  }).then(images => {
      this.setState({images:images});
      console.log(images)
  }).catch(err => {
  console.log('caught it!',err);
  })
}




      render() {

        return (

        <div className="addImg">
           <form className="imgAdditon" name="imgAdd" method="POST" onSubmit={this.onSubmit}>