Code Monkey home page Code Monkey logo

Comments (2)

amazing-gao avatar amazing-gao commented on May 31, 2024

This is an example for my application.

# upload.yaml

/cdn/upload:
  post:
    summary: Upload file to cdn
    consumes:
      - "multipart/form-data"                   # required
    x-oai-controller:
      - file: system/upload
        handler: parser
      - file: system/upload
        handler: upload
    parameters:
      - name: file
        in: formData                            # required
        type: file                              # required
        description: file
    responses:
      default:
        description: Response model
        schema:
          $ref: "#/definitions/ResponseModel"
// system/upload.js

import busboy from 'koa-busboy';

const parser = busboy();

async function upload(ctx, next) {
  {your code...}

  const files = ctx.request.files;

  {your code...}
}

export {
  parser,
  upload,
};

from koa-oai-router.

tafel avatar tafel commented on May 31, 2024

Thanks. I'm probably missing somethin obvious, but I simply copied the x-oai-controller inside my route and created /ctrl/system/upload.js where /ctrl is the path for koa-oai-router-autoloader

But I have this error message:

router boot error:  Error: args must be string or object, not undefined
    at MiddlewarePlugin.loadHandler (/vagrant/app/node_modules/koa-oai-router-middleware/src/middleware.js:47:13)
    at _.each (/vagrant/app/node_modules/koa-oai-router-middleware/src/middleware.js:30:26)
    at arrayEach (/vagrant/app/node_modules/lodash/lodash.js:516:11)
    at Function.forEach (/vagrant/app/node_modules/lodash/lodash.js:9344:14)
    at MiddlewarePlugin.handler (/vagrant/app/node_modules/koa-oai-router-middleware/src/middleware.js:29:7)
    at MiddlewarePlugin.<anonymous> (/vagrant/app/node_modules/koa-oai-router/lib/plugin.js:151:29)
    at Generator.next (<anonymous>)
    at step (/vagrant/app/node_modules/koa-oai-router/lib/plugin.js:25:191)
    at /vagrant/app/node_modules/koa-oai-router/lib/plugin.js:25:361

I'm using these koa plugins:

"@koa/cors": "^2.2.2",
"koa": "^2.6.1",
"koa-bodyparser": "^4.2.1",
"koa-busboy": "^1.2.0",
"koa-graceful-shutdown": "^1.1.0",
"koa-oai-router": "^2.0.3",
"koa-oai-router-autoloader": "^1.0.2",
"koa-oai-router-middleware": "^1.1.2",
"koa-oai-router-parameters": "^1.1.2",
"koa-pino-logger": "^2.1.3",

Thanks for your help

EDIT

Just found out that I need to put middleware: "/ctrl" in the new Router configuration. But I still have an error: without x-oai-controller, my controller is called (with a simple console.log). But with it, the route returns a 404 and I can't figure out why.

EDIT 2

Ok, I found out that I was totally mixing my paths. Now it is alright and I have my files, thanks a lot!

from koa-oai-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.