https://github.com/scalajs-io/form-data
A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
https://github.com/scalajs-io/form-data
form npm npm-module npm-package scala scalajs
Last synced: 5 months ago
JSON representation
A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
- Host: GitHub
- URL: https://github.com/scalajs-io/form-data
- Owner: scalajs-io
- Created: 2017-04-18T23:30:56.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-17T23:08:53.000Z (over 6 years ago)
- Last Synced: 2025-07-06T00:36:20.606Z (5 months ago)
- Topics: form, npm, npm-module, npm-package, scala, scalajs
- Language: Scala
- Size: 7.81 KB
- Stars: 1
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Form-data API for Scala.js
================================
[form-data](http://form-data.github.io/node-form-data-native/2.2/api/) - A library to create readable "multipart/form-data" streams.
### Description
A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads
to other web applications.
* [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
##### FormData accepts strings, buffers and readables
```scala
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.fs.Fs
import io.scalajs.npm.formdata._
import scalajs.js
val form = FormData()
form.append("my_field", "my value")
form.append("my_buffer", new Buffer(10))
form.append("my_file", Fs.createReadStream("/foo/bar.jpg"))
```
##### FormData accepts Http-response streams
```scala
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.http.{Http, ServerResponse}
import io.scalajs.npm.formdata._
import scalajs.js
val form = FormData()
Http.request("http://nodejs.org/images/logo.png", (response: ServerResponse) => {
form.append("my_field", "my value")
form.append("my_buffer", new Buffer(10))
form.append("my_logo", response)
})
```
##### FormData accepts Request streams
```scala
import io.scalajs.nodejs.buffer.Buffer
import io.scalajs.nodejs.http.{Http, ServerResponse}
import io.scalajs.npm.formdata._
import io.scalajs.npm.request.Request
import scalajs.js
val form = FormData()
form.append("my_field", "my value")
form.append("my_buffer", new Buffer(10))
form.append("my_logo", Request("http://nodejs.org/images/logo.png"))
```
### Artifacts and Resolvers
To add the `Form-data` binding to your project, add the following to your build.sbt:
```sbt
libraryDependencies += "io.scalajs.npm" %%% "form-data" % "0.5.0"
```
Optionally, you may add the Sonatype Repository resolver:
```sbt
resolvers += Resolver.sonatypeRepo("releases")
```