https://github.com/scalajs-io/multer
Middleware for handling multipart/form-data.
https://github.com/scalajs-io/multer
file-upload multer node nodejs npm npm-package scala scalajs
Last synced: 4 months ago
JSON representation
Middleware for handling multipart/form-data.
- Host: GitHub
- URL: https://github.com/scalajs-io/multer
- Owner: scalajs-io
- License: apache-2.0
- Created: 2017-02-11T22:54:33.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:10:19.000Z (about 6 years ago)
- Last Synced: 2025-01-17T22:42:30.205Z (5 months ago)
- Topics: file-upload, multer, node, nodejs, npm, npm-package, scala, scalajs
- Language: Scala
- Size: 19.5 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Multer API for Scala.js
================================
[multer](https://www.npmjs.com/package/multer) - Middleware for handling multipart/form-data.### Description
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).
### Build Dependencies
* [SBT v1.2.x](http://www.scala-sbt.org/download.html)
### Build/publish the SDK locally
```bash
$ sbt clean publish-local
```### Running the tests
Before running the tests the first time, you must ensure the npm packages are installed:
```bash
$ npm install
```Then you can run the tests:
```bash
$ sbt test
```### Examples
##### Simple file upload
```scala
import io.scalajs.npm.express._
import io.scalajs.npm.express.multer._
import scalajs.jsval 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
})
```##### Multi-part file upload
```scala
import io.scalajs.npm.express._
import io.scalajs.npm.express.multer._
import scalajs.jsval 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
})
```### Artifacts and Resolvers
To add the `Multer` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "multer" % "0.5.0"
```Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```