【发布时间】:2019-11-30 07:21:32
【问题描述】:
我想将图像插入到从 接收的 mysql 数据库中,并在获取后希望使用节点将其显示在 上并做出反应
下面是我的nodejs代码。
const {ISBN,publisher,category,edition,image,title,price,quantity,author,}=req.query
console.log(req.query)
const insertIntoBooks=`INSERT into BOOKS(ISBN,publisher,category,edition,image,title,price,quantity,author) VALUES('${ISBN}','${publisher}','${category}','${edition}','${image}','${title}',${price},${quantity},'${author}')`
connection.execute(insertIntoBooks).then(resp=>res.json({data:'success'})).catch(err=>res.json({data:'error'}))
})
上面你可以看到我收到了一张图片,这张图片就是我想保存在 Mysql 中的。 下面是我的反应代码
props.startInsertingBook(`http://localhost:3300/books/add?title=${title}&price=${price}&quantity=${quantity}&author=${authorName}&ISBN=${ISBN}&image=${image}&publisher=${publisher}&edition=${edition}&category=${category}`)
下面是我的 redux Action 代码。
return(dispatch)=>{
return fetch(`${url}`).then(resp=>resp.json()).then(({data})=>{
console.log(data);
if(data==='success'){
return toastr.success('Success','Book added Successfuly')
}else{
return toastr.error('Error','Error in submitting')
}
}).catch(err=>toastr.error('oops','error occur due to lost in coonectivity'))
}
}```
【问题讨论】:
-
我相信您共享的
fetch代码将适用于GET方法,仅适用于POST方法fetch采用另一个参数options。您可以查看获取文档here
标签: mysql node.js reactjs redux fetch