middleware/multipart

module:middleware/multipart

Description:
  • Parse multipart content for uploaded files, uses formidable package.

    Store parsed data in the context.files and context.body.

    Global mode

    The middleware handles uploads automatically for all paths posts via -middleware-multipart-enable = true

    This is equivalent of running on startup: api.app.post("*", middleware.multipart)

    Config bkjs.conf

    middleware-multipart-enable = true
    

    Then in the code just check for files:

    api.app.post("/upload", (context, next) => {
        if (context.files.file) ....
    })
    

    Programmatic mode

    To handle uploads for known endpoints is to call it for all known paths at once before the actual upload handlers

    
    api.app.post("/upload/", middleware.multipart);
    
    api.app.post("/upload/icon", (context, next) => {
    
    api.app.post("/upload/icon", (context, next) => {
    
Source:

Methods

(static) configureMiddleware()

Description:
  • Start global middleware, enable multipart parser for all endpoints

Source:

(static) handle(context, next)

Description:
  • Multipart middleware

Source:
Parameters:
Name Type Description
context RequestContext
next function()