使用graphql-upload,apollo-server-fastify和NestJS代码优先方法上传文件

使用以下软件包/技术组合(未列出其对应的依存关系)来从服务器上的客户端接收文件上传的正确实现是什么:

  • graphql-upload
  • apollo-server-fastify
  • @nestjs/platform-fastify(代码优先方法)

理想情况下,我们正在尝试使用nestJS GraphQL代码优先技术(除多个文件而不是一个文件)来实现以下内容(来自apollo server file uploads

const { ApolloServer,gql } = require('apollo-server');

const typeDefs = gql`
  type File {
    filename: String!
    mimetype: String!
    encoding: String!
  }

  type Query {
    uploads: [File]
  }

  type Mutation {
    singleUpload(file: Upload!): File!
  }
`;

const resolvers = {
  Query: {
    uploads: (parent,args) => {},},Mutation: {
    singleUpload: (parent,args) => {
      return args.file.then(file => {
        //Contents of Upload scalar: https://github.com/jaydenseric/graphql-upload#class-graphqlupload
        //file.stream is a node stream that contains the contents of the uploaded file
        //node stream api: https://nodejs.org/api/stream.html
        return file;
      });
    },};

const server = new ApolloServer({
  typeDefs,resolvers,});

server.listen().then(({ url }) => {
  console.log(`? Server ready at ${url}`);
});

现在,我的前端正在使用此突变将文件正确发送到服务器:

gql`
  mutation uploadObjects($files: [Upload!]!) {
    uploadObjects(files: $files) {
      bucketKey
    }
  }
`;

以下是与文件二进制文件一起发送的请求图像的链接:

jio123456 回答:使用graphql-upload,apollo-server-fastify和NestJS代码优先方法上传文件

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3155868.html

大家都在问