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

Uploading image via the GraphQL API: PayloadTooLargeError: request entity too large #1943

Closed
jordanoverbye opened this issue Nov 10, 2019 · 3 comments

Comments

@jordanoverbye
Copy link
Contributor

I'm using Puppeter to generate a screenshot of a website, which will return a File Buffer. If I save this file to disk its roughly around ~50kb - so pretty small.

I want to save this file as a field in Keystone, so I'm trying to upload it via the GraphQL API but I get the following error:

PayloadTooLargeError: request entity too large

I'm using request to handle the request.

const id = 'ID_I_WANT_TO_UPDATE'
const fileBuffer = 'FILE_BUFFER_FROM_PUPPETER'

await request({
  method: 'POST',
  url: 'KEYSTONE_API_URL',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({
    variables: { image: fileBuffer, id, },
    query: `mutation UPDATE_POST($id, ID!, $image: Upload!) {
      updatePost(id: $id, data: { image: $image })
    }`
  })
})
@jesstelford
Copy link
Contributor

Assuming the Post.image field is a File or CloudinaryImage type, it needs to be submitted as a multipart form, not json type. That's because we use the Apollo Server scalar Upload type.

You can either use apollo-client to handle the intricacies for you: https://blog.apollographql.com/file-uploads-with-apollo-server-2-0-5db2f3f60675#615d

Or Piece it together yourself based on the spec: https://github.com/jaydenseric/graphql-multipart-request-spec

@ralexrdz
Copy link
Contributor

I'm having same issue when setting an image block on a Content Type (Rich Text Editor).

I would love to have it saved as a File with a LocalAdapter, than saving it as data:image

Any idea?

@dimaip
Copy link

dimaip commented Feb 14, 2021

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

4 participants