uploading images with filepond in an express ejs project

162 Views Asked by At

I'm working on a project that uses express.js for backend and the ejs rendering template for frontend. I've uploaded some images using filepond and the images were converted to base64. However, while viewing the output on the browser, the images look as though they're broken (with a small square at the top-left corner).

I need help with getting this fixed. Here's the code for the function to save the images and convert to base64:

function saveCover(book, coverEncoded) {
    if (coverEncoded == null) return;
    const cover = coverEncoded;
    if (cover != null && imageMimeTypes.includes(cover.type)) {
      book.coverImage = new Buffer.from(cover.data, "base64");
      book.coverImageType = cover.type;
    }
}
1

There are 1 best solutions below

0
On

The problem I believe will be coming from how you are retrieving the image. If the code you've shown above saves the image (i.e you are seeing some data in the database), then you should focus your attention on the code that retrieves the image to display on the webpage.