0

I'm trying to create a form in which users should be able to upload images(I know how to upload and display string, int data types to/from mysql db) and display images from mysql db in pug template engine.

I'm stuck at this point: Imagine you want to sell your any product and you're filling out ecommerce website form about product details, such as, price, name, category etc.

The thing I want to do is to know how to upload images to mysql db and display them in browser using pug template engine.

I would really appreciate if anybody can help me figure it out.

juanlumn
  • 6,155
  • 2
  • 30
  • 39

1 Answers1

0

I suggest you store the images elsewhere, because storing in db will make db grows very fast which make it very troublesome to backing up.

also, it's difficult to use cdn with it.

More on this topic at: Can I store images in MySQL

if you're insisted on using it, you can use BLOB data type

CREATE TABLE 'test'.'pic' (
    'idpic' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
    'caption' VARCHAR(45) NOT NULL,
    'img' LONGBLOB NOT NULL,
  PRIMARY KEY ('idpic')
)

you then can convert that blob to base64 to display it in pug template.

again, there are many down sides with this approach so I suggest you look at the linked topic above.

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54