Search code examples
gographqlgqlgen

set graphql's max file upload size (golang)


I wrote an server in golang which to which files can be uploaded using multipart form. I want to extend the maximum upload size.

On the documentation site of the implementation I'm using I found following:

  • uploadMaxSize This option specifies the maximum number of bytes used to parse a request body as multipart/form-data.

  • uploadMaxMemory This option specifies the maximum number of bytes used to parse a request body as multipart/form-data in memory, with the remainder stored on disk in temporary files.

(here: https://github.com/99designs/gqlgen/blob/master/docs/content/reference/file-upload.md#Configuration)

Where can this configuration be applied?

Thanks


Solution

  • You can apply these configuration options in your GraphQL handler, like:

    var mb int64 = 1 << 20
        uploadMaxMemory := handler.UploadMaxMemory(32 * mb)
        uploadMaxSize := handler.UploadMaxSize(50 * mb)
    
        http.Handle("/query", handler.GraphQL(exec, uploadMaxMemory, uploadMaxSize))