小编Ast*_*gie的帖子

如何使用GraphQL将图像上传到AWS S3?

我正在上传一个base64字符串,但GraphQL被挂起了.如果我将字符串切片少于50,000个字符就可以了.在50,000个字符之后,graphQL永远不会使其成为解析函数,但不会产生错误.在较小的字符串上,它工作得很好.

const file = e.target.files[0];
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = () => {
  const imageArray = reader.result;
  this.context.fetch('/graphql', {
    body: JSON.stringify({
      query: `mutation s3Upload($img: String!) {
        s3Upload(file: $img) {
          logo,
        }
      }`,
      variables: {
        img: imageArray,
      },
    }),
  }).then(response => response.json())
  .then(({ data }) => {
    console.log(data);
  });
}

const s3Upload = {
    type: S3Type,
    args: {
      file: { type: new NonNull(StringType) },
    },
    resolve: (root, args, { user }) => upload(root, args, user),
};

const S3Type …
Run Code Online (Sandbox Code Playgroud)

javascript amazon-s3 reactjs graphql aws-appsync

9
推荐指数
1
解决办法
3332
查看次数

标签 统计

amazon-s3 ×1

aws-appsync ×1

graphql ×1

javascript ×1

reactjs ×1