【发布时间】:2021-05-29 23:08:53
【问题描述】:
我正在尝试使用 apolloclient 和 GraphQL 上传文件,但出现 GraphQL 错误:createReadStream 不是函数。不知道怎么解决
Mutation: {
uploadFile: async (parent, { file }) => {
const { createReadStream, filename, mimetype, encoding } = await file
const stream = createReadStream()
const pathName = path.join(__dirname, `/public/images/${filename}`)
await stream.pipe(fs.createWriteStream(pathName))
return {
url: `http://localhost:3000/images/${filename}`,
}
},
}
【问题讨论】:
-
请求正文片段?
-
您似乎没有正确导入
fs?那时fs喜欢什么?尝试将其打印到控制台或使用调试工具检查函数闭包。
标签: javascript reactjs graphql