node.js - graphql apollo-server 中的文件上传错误
问题描述
我正在学习graphql。我关注了这篇文章https://dev.to/dnature/handling-file-uploads-with-apollo-server-2-0-14n7#:~:text=With%20Apollo%20Server%202.0% 2C%20you,a%20cloud%20storage%20provider%20 代替。用于使用 graphql apollo-server 上传文件,但在图像文件夹中为响应和空文件获得无限缓冲。
我确定错误是在以下两个文件中
解决方案
您需要graphql-upload
使用yarn add graphql-upload
. 然后你需要在 ApolloServer 创建到主服务器文件中做一些更改,
const apolloServer = new ApolloServer({
schema,
resolvers,
uploads: false, // add this
});
然后你需要从你的主服务器文件中添加graphqlUploadExpress
中间件,graphql-upload
app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }));
有关更多信息,请参阅此 github 问题https://github.com/MichalLytek/type-graphql/issues/37#issuecomment-592467594
推荐阅读
- javascript - Express Router 端点的 CORS 问题
- javascript - 在 JavaScript 中模拟汽车旋转
- python - 在 Python 中将数字排列成列表互质对的程序
- android - [Android]调用API申请清洁架构报错如何处理?
- python - 安装虚拟环境时出错
- redis - redis ERR 未知命令'UNLINK'
- javascript - 在 Vue Storybook 中导入错误的路径
- javascript - 404 在 nuxt.js 上找不到 sitemap.xml
- nginx - 如何在 Nginx 中包含多个 js_include 标签
- python - 来自输入文件 csv 的 itertools.combination 和列表