将图像上传到GraphQL服务器

Vla*_*nov 3 javascript node.js reactjs graphql react-apollo

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

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

{ preview: 'blob:http://localhost:3000/c622b0bd-3f0d-4f52-91f4-7676c8534c59' }
Run Code Online (Sandbox Code Playgroud)

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

leo*_*ncc 6

另一种方法是在上载之前将二进制映像转换为客户端的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'
    }
  })
});
Run Code Online (Sandbox Code Playgroud)


Vla*_*nov 5

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

  • 您可以添加代码或github链接吗?不胜感激!我发现的代码很少。谢谢! (2认同)