iyobo / amala

NodeJs Framework for creating REST API endpoints with Typescript decorators. Supports API versioning, OpenAPI3 and docker. Powered by Koa 2+ and Nigerian food (amala+ewedu)
MIT License
51 stars 7 forks source link

multer support for amala #47

Open redsomber opened 1 year ago

redsomber commented 1 year ago
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, './uploads/')
  },
  filename: function (req, file, cb) {
    cb(null, `${file.fieldname}-${Date.now()}-${file.originalname}`)
  },
})
const upload = multer({ storage: storage })

@Controller('/')
class UploadController {
  @Flow([upload.single('image')])
  @Post('/upload')
  upload(@File() files: Record<string, File>) {
    console.log(files)
  }
}

this is my code that doesn't give any errors at all. I get the file in logs, but I can't upload it.

Without using amala with only koa, everything works fine. I assume that the problem is a different way of processing the request, since it is impossible to access the fields through amala

originalname fieldname and etc...

Therefore, multer receives incorrect data, I cannot solve the problem in any way.

is there a way to make friends with amala and multer?

iyobo commented 1 year ago

Try setting bodyParser: false in bootstrap function. This means you get to setup your own body parsing.

Would advise adding that to bootstrapFunction's flow parameter.