Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Main
  • Accessing Multipart body
  • Mandarine.MandarineMVC.MultipartFormData

Was this helpful?

  1. Mandarine MVC

Multipart Form Data

PreviousServing Static ContentNextSessions

Last updated 4 years ago

Was this helpful?

Main

Mandarine allows you to receive multipart/form-data in your requests & endpoints. You can receive both properties and files from a multipart request.

Accessing Multipart body

Mandarine automatically handles the reading and parsing of your multipart/form-data request. This means, you do not have to do any extra code in order to access its data and the different structure it may have such as properties or files.

To access your multipart body, you will need to make use of the decorator @RequestBody() which is part of .

If the content type of your request is equivalent to multipart/form-data then @RequestBody() will return an object of Mandarine.MandarineMVC.MultipartFormData which will contain your properties and files.

Mandarine.MandarineMVC.MultipartFormData

Mandarine.MandarineMVC.MultipartFormData is an interface which contains the following structure

export interface MultipartFormData {
    fields?: {
        [prop: string]: any
    },
    files?: {
        [filename: string]: Uint8Array | Uint16Array | Uint32Array | BigUint64Array
    }
}

The key of the a property (MultipartFormData.fields) is the key of the Multipart form. However, the key of a filename is the name of the file name which would mean if you are sending a file with the name of image.png you would access to it by `

let obj: MultipartFormData = ...
obj.files["image.png"]

Note Properties/fields can return anything but most likely a string, number or boolean. However, files return a binary interpretation that can be used by both Deno & Typescript. In most cases, a file will return Uint8Array but many binary interpretations are available.

HTTP Parameter Decorators