99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.86k stars 1.15k forks source link

Unable to override MaxUploadSIze for file upload #2403

Open jh-chee opened 1 year ago

jh-chee commented 1 year ago

What happened?

This is similiar to #1780.

I was trying out the file upload example and set the MaxUploadSize to 1 GB under server/server.go.

I then uploaded a file with size of 576 MB. The error message was {"errors":[{"message":"failed to parse multipart form, request body too large"}],"data":null}.

What did you expect?

The upload for 576 MB should be successful based on the configuration set.

I tried again with a 31 MB file and the upload was successful. The hard limit seems to be at 32 MB.

Minimal graphql.schema and models to reproduce

Schema is based from file upload example.

scalar Upload

type File {
    id: Int!
    name: String!
    content: String!
    contentType: String!
}

input UploadFile {
    id: Int!
    file: Upload!
}

type Mutation {
    singleUploadWithPayload(req: UploadFile!): File!
}

versions

atzedus commented 1 year ago

Probably there is error in example, try to create you custom server handler from scratch based on NewDefaultServer method, like this:

s := handler.New(schema)

s.AddTransport(transport.Websocket{
    KeepAlivePingInterval: 10 * time.Second,
}) 

s.AddTransport(transport.Options{})
s.AddTransport(transport.GET{})
s.AddTransport(transport.POST{})
s.AddTransport(transport.MultipartForm{MaxUploadSize: 1000 * (1 << 20)})

s.SetQueryCache(lru.New(1000))

s.Use(extension.Introspection{})

s.Use(extension.AutomaticPersistedQuery{
    Cache: lru.New(100),
})

In example NewDefaultServer already adds MultipartForm transport, and when you adds second one it not used in request.

tcastelly commented 1 year ago

thx @atzedus it works for me. I just have to increase the MaxMemory too

mb := int64(1 << 20)
graphQueryHandler.AddTransport(transport.MultipartForm{
    MaxUploadSize: 50 * mb,
    MaxMemory:     50 * mb,
})