3

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

stukoi
  • 33
  • 4

1 Answers1

3

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))
heisenb0rg
  • 168
  • 13
  • 1
    Thank you very much that helped me a lot. Althrough `handler.GraphQL(...)` is marked as deprecated in my gql verision, I found another way: You can create a new server with `srv := handler.New(generated.NewExecutableSchema(config))` and then `srv.AddTransport(transport.MultipartForm{MaxUploadSize: 500 * MB,MaxMemory: 100 * MB,})`. Note that calling `handler.NewDefaultServer` and then adding the transport will not have the desired effect; transport is already added in `NewDefaultServer()` and will not be overridden. – stukoi Mar 06 '23 at 13:48
  • This issue might be relevant: https://github.com/99designs/gqlgen/issues/1631 – stukoi Mar 06 '23 at 13:59