Home

Awesome

think-payload

npm Build Status Coverage Status

Payload for Thinkjs 3.0

Install

$ npm install think-payload --save

Usage

config file src/config/middleware.js

const payload = require('think-payload');

module.exports = [{
  handle: payload,
  options: {}
}]

Data in Controller

this.ctx.body = this.ctx.request.body

// use `rawBody` to get raw request body
this.ctc.request.rawBody

this.ctx.request.body

Options

The following options are parsing form data, especially file uploads.

Errors

This module creates errors depending on the error condition during reading. The error may be an error from the underlying Node.js implementation, but is otherwise an error created by this module, which has the following attributes:

Types

The errors from this module have a type property which allows for the progamatic determination of the type of error returned.

encoding.unsupported

This error will occur when the encoding option is specified, but the value does not map to an encoding supported by the iconv-lite module.

entity.too.large

This error will occur when the limit option is specified, but the stream has an entity that is larger.

request.aborted

This error will occur when the request stream is aborted by the client before reading the body has finished.

request.size.invalid

This error will occur when the length option is specified, but the stream has emitted more bytes.

stream.encoding.set

This error will occur when the given stream has an encoding set on it, making it a decoded stream. The stream should not have an encoding set and is expected to emit Buffer objects.