简体   繁体   中英

File upload error in graphql apollo-server

I am learning graphql .I followed this article 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%20instead . for file upload using graphql apollo-server but get endless buffering for response and empty file in images folder.

I am certain error is in following two files

mutation file

schema file

You need to add graphql-upload package using yarn add graphql-upload . Then you need to do some changes inside ApolloServer creation into the main server file,

const apolloServer = new ApolloServer({
    schema,
    resolvers,
    uploads: false, // add this
  });

then you need to add graphqlUploadExpress middleware from graphql-upload inside your main server file,

  app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }));

For more refer to this github issue https://github.com/MichalLytek/type-graphql/issues/37#issuecomment-592467594

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM