Next.js Discord

Discord Forum

Urgent help please, postgreSQL images into nextjs

Unanswered
In&Out posted this in #help-forum
Open in Discord
Hey folks, im storing images inside pgSQL, with bytea in my table, and i want to put them into my nextjs page, how do i do that?

4 Replies

This is what i have
                <img
                    src={`data:image/jpeg;base64,${newPage.image.replace(/\n/g, '')}`}
                    alt={newPage.title}
                    className={styles.VestiBoxImage}
                  />
export async function fetchNewsByPageSlug(slug: string) {
  try {
    console.log(slug,"NEWS SLUG")
    const res = await query(`SELECT title, context, encode(image_content, \'base64\') AS image, published_at FROM "news" WHERE "page_slug" = $1`,[slug]);
    console.log(res.rows)
    return res.rows.map((row) => ({
      title: row.title,
      context: row.context,
      date: new Date(row.published_at).toLocaleDateString("sr-RS"),
      image: `data:image/jpeg;base64,${row.image}`,
    }));
  } catch (err) {
    console.error("Failed to fetch news:", err);
    return [];
  }
}
[
  {
    title: 'nake vest',
    context: '<p>Neka opasna vest haos</p>',
    image: '/9j/4AAQSkZJRgABAQAAAQABAAD/4gIcSUNDX1BST0ZJTEUAAQEAAAIMbGNtcwIQAABtbnRyUkdC\n' +
      'IFhZWiAH3AABABkAAwApADlhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAA\n' +