Make File Input: In your HTML, make a file input:
<input type="file">
Send Request: In your client JavaScript, send a POST
request with a
FormData
object:
let formData = new FormData()
formData.append(`yourKey`, yourFileInput.files[0])
let request = new XMLHttpRequest()
request.open(`POST`, `/your-route`)
request.send(formData)
Include Module:
let fileUpload = require(`express-fileupload`)
Save File: In your file upload endpoint, get the
file from the request, and save it to the new folder:
let file = request.files.yourKey
file.mv(`${__dirname}/your-folder/${file.name}`)