0

Im making a web app, using node.js, express.js and mongodb and trying get my contact form done. I would like site visitors to contact me via the form where they can put their name, email and message, along with an uploadable file image so they can show me what they want to be done as a sample through an image.

It seems like every websites have this functionailiry but I cant seem to find the answer Im looking for. Any help and guides would be appreciated.

2 Answers2

1

i think you could use this library i've just found for uploading files with Javascript by using a file dialog: https://fineuploader.com/demos.

I think your issue is pretty much solved after that because for what concerns the form, you may easily create the input tags in HTML and then get data from them by using NodeJS.

Argex
  • 1
  • 2
0

To upload files you need to use a form-data handler. I use multer:

npm i multer

You upload a file like this:

const multer  = require('multer')
const upload = multer({ dest: 'uploads' })

app.post('/profile', upload.single('image'), (req, res)) {
   //Now the image is uploaded in uploads folder you just need to send it back
}

Note that image is a form's input name.

For infroamtion on how to send the image see this

Look also at the docs for multer

If you don't want to store image you can use then fs module to delete it.