4

我正在使用react-dropzonegraphql-server-express-upload在 GraphQL Apollo 中上传图像。在我的客户端中,文件如下所示:客户端上的文件

但是在服务器中,当我记录它时,它看起来像这样:

{ preview: 'blob:http://localhost:3000/c622b0bd-3f0d-4f52-91f4-7676c8534c59' }

我正在按照graphql-server-express-upload自述文件中的说明进行操作,但到目前为止还没有运气。如何获得完整的图像?

4

2 回答 2

8

另一种方法是在客户端将二进制图像转换为 BASE64,然后再上传,然后将图像填充为作为突变参数传递的 GraphQLInputObjectType 上的 BASE64 字符串。在服务器上,该字段可以简单地保存在数据库列中。例如:

const UserInputType = new GraphQLInputObjectType({
  name: 'UserInput',
  description: 'The user of our system',

  fields: () => ({
    username: {
        type: GraphQLString,
        description: 'Name of the user'
    },
    image: {
        type: GraphQLString,
        description: 'Image of the user'
    }
  })
});
于 2017-09-03T10:02:19.890 回答
6

我最终使用了apollo-upload-client,效果很好!

于 2017-04-01T18:11:44.940 回答