To upload a file you need to:
- adjust the form on the front-end. Take a look at
upload-pictures.hbs
. โ - On the back-end you need to set up a route that processes the data coming from the form. Since form that contain files send their data in a different encoding type (multi-part/formdata), you need a package that can parse data in this datatype. This package is multer. Check the npm page for multer. Make sure your field-names match.:white_check_mark:
- Save a reference to the file in the database. This example uses a simple Picture model, but you can include a path in any kind of model. โ
General tip: use Postman ๐ฆ to first implement the route. If you got that to work, you can start focussing on the front-end. This will not only speed up your workflow considerably, but it will also become easier to create automated tests later as well!