0

I'm trying to get a Multipart POST to work with fastify-multipart, but whenever I post a multipart file to the endpoint my service crashes with the following error:

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)

Am I missing a dependency or something like this?

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

In index.js this is the code:

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 seems to be undefined.

chris
  • 600
  • 7
  • 21

1 Answers1

1

Only the fastify-multipart v1 is compatible with fastify v2

Note that the API is totally changed from v3 and above, so you need to update your fastify version or downgrade your plugin and change the payload management.

Manuel Spigolon
  • 11,003
  • 5
  • 50
  • 73