fastify-multipart 崩溃服务

fastify-multipart crashes service

我正在尝试让一个多部分 POST 与 fastify-multipart 一起工作,但是每当我 post 一个多部分文件到端点时,我的服务就会崩溃并出现以下错误:

req.raw[kMultipart] = true
                      ^

TypeError: Cannot set property 'Symbol(multipart)' of undefined
    at Parser.setMultipart [as fn] (/service/node_modules/fastify-multipart/index.js:24:23)
    at ContentTypeParser.run (/service/node_modules/fastify/lib/contentTypeParser.js:103:27)
    at handleRequest (/service/node_modules/fastify/lib/handleRequest.js:35:39)
    at onRunMiddlewares (/service/node_modules/fastify/lib/middleware.js:22:5)
    at Holder.done (/service/node_modules/middie/middie.js:90:9)
    at xXssProtection (/service/node_modules/x-xss-protection/dist/index.js:47:13)
    at Holder.done (/service/node_modules/middie/middie.js:112:11)
    at nosniff (/service/node_modules/dont-sniff-mimetype/dist/index.js:5:9)
    at Holder.done (/service/node_modules/middie/middie.js:112:11)
    at xDownloadOptionsMiddleware (/service/node_modules/ienoopen/index.js:5:5)

我是否遗漏了依赖关系或类似的东西?

"fastify": "^2.0.0",
"fastify-multipart": "^4.0.6",

在 index.js 中,这是代码:

const kMultipart = Symbol('multipart')

function setMultipart (req, payload, done) {
  // nothing to do, it will be done by the Request.multipart object
  req.raw[kMultipart] = true
  done()
}

req.raw 似乎未定义。

只有 fastify-multipart v1 兼容 fastify v2

请注意,API 与 v3 及更高版本完全不同,因此您需要更新您的 fastify 版本或降级您的插件并更改负载管理。