此问题是由于Fastify的默认解析器(fastify-multipart)不支持使用Busboy的multipart/form-data格式而引起的。解决方法是使用fastify-multer插件,它支持multipart/form-data并使用multer作为解析器。
代码示例:
npm install fastify-multer
const fastify = require('fastify')({ logger: true }) const multer = require('fastify-multer')
fastify.register(multer.contentParser)
fastify.post('/upload', async function (req, rep) { const uploadedFile = req.body.file // 访问上传的文件 // 处理上传的文件 })
await fastify.listen(3000)
这就是使用fastify-multer解决Busboy with Fastify gives Unsupported Media Type: multipart/form-data; boundary错误的方法。
上一篇:busboyonfieldandonfilenotfiring
下一篇:BusboywithFastifygivesUnsupportedMediaType:multipart/form-data;boundary