spry_multer 1.0.0

SDKdartflutter
Platformandroidioswindowslinuxmacos

Spry multer is a Spry framework middleware & extension for handling multipart/form-data, which is primarily used for uploading files.

Spry Multer

Spry multer is a Spry framework middleware & extension for handling multipart/form-data, which is primarily used for uploading files.

pub version

Installation

Add the following to your pubspec.yaml file:

dependencies:
  spry_multer: any

Or install via command line:

$ dart pub add spry_multer

Getting Started

Spry multer is zero-configuration and only needs to be imported to use:

import 'package:spry/spry.dart';
import 'package:spry_multer/spry_multer.dart';

handler(Context context) async {
  final multipart = await context.request.multipart();

  //...
}

Basic usage example:

Note: Don't forget to add enctype="multipart/form-data" to your form.

<form action="/upload" method="post" enctype="multipart/form-data">
  <input type="file" name="file" />
</form>
import 'package:spry/spry.dart';
import 'package:spry_multer/spry_multer.dart';

handler(Context context) async {
  final multipart = await context.request.multipart();

  final file = multipart.files.first;

  //...
}

Configuration

Spry multer can be configured with the following options:

final multer = Multer(encoding: utf8); // default

spry.use(multer);

Note: Multer allow you to configure the encoding of the incoming form data. By default, Multer uses Spry encoding.

The Spry encoding defaults to utf8 and can be changed by setting the Spry.encoding property.

API

Multer

Options:

NameTypeDefaultDescription
encodingEncodingSpry.encodingThe encoding of the incoming form data.

Static methods:

NameDescription
of(context)Get the Multer instance from the Context.
createMultipart(request)Create a Multipart instance from the Request.

methods:

NameDescription
call(context, next)The middleware handler.

Multipart

Properties:

NameTypeDescription
filesIterable<File>The list of uploaded files.
fieldsIterable<String>The list of uploaded fields.

File

Properties:

NameTypeDescription
filenameStringThe name of the file on the user's computer.
contentTypeContentTypeThe content type of the file.

Note: The File class extends Stream<List<int>> and can be used as a Stream of bytes.

Extension on Request

NameDescription
multipart()Find or parsed create a Multipart instance from the Request.