Skip to content

Simple express file upload middleware that wraps around connect-busboy

License

Notifications You must be signed in to change notification settings

scalajs-io/express-fileupload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-fileupload API for Scala.js

express-fileupload - Simple express file upload middleware that wraps around connect-busboy.

Description

Simple express middleware for uploading files.

Build Dependencies

Build/publish the SDK locally

 $ sbt clean publish-local

Running the tests

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

Example

import 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!")
          })
      }
    }
})

Artifacts and Resolvers

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") 

Releases

No releases published

Packages

No packages published

Languages