I used PHPmyAdmin as my localhost, Axios to do backend functions and react to display on the webpage, I created a table that stores an ID and a Blob, since blob can store image data. I used state hooks and render each of the item to be displayed on the page but when I render the page, a broken image has displayed. I tried to console.log() on that image data and it displayed as {type: 'Buffer', data: Array(50639)} on the console browser.
In short, I am trying to retrieve an image from a table in the localhost and display it on the browser
React
function ProjectCard() {
const [projectCard, setProjectCard] = useState([]);
const instance = axios.create( {
baseURL: "http://localhost:3001/api",
});
useEffect(() => {
instance.get("/getAvailableProjects").then((response) => {
setProjectCard(response.data);
});
}, []);
return (
<div className="row g-4 py-4 border-bottom">
{projectCard.map((val) => {
return (
console.log(val.PROJECT_IMAGE) {/* displayed as {type: 'Buffer', data: Array(50639)} */}
<div className="col-lg-3 col-md-6 mb-2" key={val.PROJECT_ID}>
<img id="project-img" src={val.PROJECT_IMAGE} className="img-fluid" /> {/* BROKEN IMAGE */}
</div>
);
})}
</div>
)
};
export default ProjectCard;
Server
app.get("/api/getAvailableProjects", (req, res) => {
const sqlQuery = "SELECT *, from projectdetail";
db.query(sqlQuery, (_error, result) => {
res.send(result);
});
});
Is there a way to convert this blob data into an actual image?