Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graphql-yoga文件上传的问题 #54

Open
Triment opened this issue Mar 30, 2023 · 3 comments
Open

graphql-yoga文件上传的问题 #54

Triment opened this issue Mar 30, 2023 · 3 comments

Comments

@Triment
Copy link
Owner

Triment commented Mar 30, 2023

stackoverflow

另一个关于此的讨论

后者给出了yoga的另一种文件上传的写法

profileImageUpload: async (_, { file }: { file: File }) => {
      // get readableStream from blob
      const readableStream = file.stream()
      const stream = readableStream.getReader()
      console.log('file', file.type)
      let _file: Buffer | undefined
      while (true) {
        // for each iteration: value is the next blob fragment
        const { done, value } = await stream.read()
        if (done) {
          // no more data in the stream
          console.log('all blob processed.')
          break
        }

        if (value)
          _file = Buffer.concat([_file || Buffer.alloc(0), Buffer.from(value)])
      }

      if (_file) {
        const image = sharp(_file)
        const metadata = await image.metadata()
        console.log(metadata, 'metadata')
        try {
          const image = await sharp(_file).resize(600, 600).webp().toBuffer()
          fs.writeFileSync('test.webp', image)
          console.log(image, 'image')
        }
        catch (error) {
          console.error(error)
        }
      }

      return 'a'
    },
@Triment
Copy link
Owner Author

Triment commented Mar 30, 2023

https://stackoverflow.com/questions/49053193/nodejs-request-how-to-send-multipart-form-data-post-request

Yoga 是通过解析request对象实现上传的,这是关于发送数据的讨论

@Triment
Copy link
Owner Author

Triment commented Mar 30, 2023

关于 File 标准api在浏览器中的数据控制和文件规则用法https://web.dev/read-files/#read-metadata

@Triment
Copy link
Owner Author

Triment commented Mar 30, 2023

express关于blob的pr

expressjs/express#4807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant