express-fileupload - Simple express file upload middleware that wraps around connect-busboy.
Simple express middleware for uploading files.
$ sbt clean publish-localBefore running the tests the first time, you must ensure the npm packages are installed:
$ npm installThen you can run the tests:
$ sbt testimport io.scalajs.nodejs.os.OS
import io.scalajs.npm.express._
import io.scalajs.npm.express.fileupload._
val app = Express()
app.use(ExpressFileUpload())
app.post("/upload", (req: Request with UploadedFiles, res: Response) => {
if (req.files.isEmpty) res.send("No files were uploaded.")
else {
// The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
req.files foreach { case (name, file) =>
// Use the mv() method to place the file somewhere on your server
file.mv(s"${OS.tmpdir()}/$name", { err =>
if (err != null) res.status(500).send(err) else res.send(s"File '$name' uploaded!")
})
}
}
})To add the express-fileupload binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "express-fileupload" % "0.5.0"Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")