multer - Middleware for handling multipart/form-data.
Multer is a node.js middleware for handling multipart/form-data, which is primarily used for uploading files. It is written on top of busboy for maximum efficiency.
NOTE: Multer will not process any form which is not multipart (multipart/form-data).
$ sbt clean publish-local
Before running the tests the first time, you must ensure the npm packages are installed:
$ npm install
Then you can run the tests:
$ sbt test
import io.scalajs.npm.express._
import io.scalajs.npm.express.multer._
import scalajs.js
val app = Express()
val upload = Multer(new MulterOptions(dest = "uploads/"))
app.post("/profile", upload.array(), (req: Request, res: Response, next: js.Function) => {
// req.body contains the text fields
})
import io.scalajs.npm.express._
import io.scalajs.npm.express.multer._
import scalajs.js
val upload = Multer(new MulterOptions(dest = "uploads/"))
val app = Express()
app.post("/profile", upload.single("avatar"), (req: Request, res: Response, next: js.Function) => {
// req.file is the `avatar` file
// req.body will hold the text fields, if there were any
})
app.post("/photos/upload", upload.array("photos", 12), (req: Request, res: Response, next: js.Function) => {
// req.files is array of `photos` files
// req.body will contain the text fields, if there were any
})
val cpUpload = upload.fields(js.Array(new MulterField(name = "avatar", maxCount = 1), new MulterField(name = "gallery", maxCount = 8)))
app.post("/cool-profile", cpUpload, (req: Request, res: Response, next: js.Function) => {
// req.files is an object (String -> Array) where fieldname is the key, and the value is array of files
//
// e.g.
// req.files["avatar"][0] -> File
// req.files["gallery"] -> Array
//
// req.body will contain the text fields, if there were any
})
To add the Multer
binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "multer" % "0.5.0"
Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")