gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

Fail to upload file

Open KingWu opened this issue 1 year ago • 4 comments

What happened?

Upgrade from 0.13.0 to 0.17.44 and go from 1.16 to 1.22

What did you expect?

Can upload file previously, but right now throw the following issue

{
	"errors": [
		{
			"message": "failed to parse multipart form"
		}
	],
	"data": null
}

The request body show follow

 POST /portal?lang=en_US HTTP/1.1
> Host: localhost:8080
> User-Agent: insomnia/8.6.1
> Content-Type: multipart/form-data; boundary=X-INSOMNIA-BOUNDARY
> Authorization: Bearer xxxxxxxxxx
> Accept: */*
> Content-Length: 3021

| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="operations"
| {"query":"mutation ($file: Upload!) .........
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="map"
| {"0":["variables.file"]}
| --X-INSOMNIA-BOUNDARY
| Content-Disposition: form-data; name="0"; filename="logo.svg"
| Content-Type: image/svg+xml
| <svg width="110" height="44" viewBox="0 0 110 44" ............
| --X-INSOMNIA-BOUNDARY--

versions

  • go run github.com/99designs/gqlgen version? 0.17.44
  • go version? 1.22

KingWu avatar Feb 16 '24 15:02 KingWu

Try different go version with gqlgen version

gqlgen v0.17.33 with go v1.18 => Not work gqlgen v0.17.10 with go v1.16 => Not work gqlgen v0.17.0 with go v1.16 => Not work

KingWu avatar Feb 18 '24 14:02 KingWu

gqlgen v0.16.0 with go v1.16 => Work

gqlgen upgrade to v0.17.x will cause upload fail issue

KingWu avatar Feb 18 '24 16:02 KingWu

Have you tried apollo upload client?

UnAfraid avatar Feb 18 '24 19:02 UnAfraid

i did't use apollo as my client. For gqlgen, after 0.17.0, it assume the client is using apollo client?

KingWu avatar Feb 20 '24 11:02 KingWu

Any update for the issue? My request show as below

operations= {"query":"mutation ($file: Upload!) {\n\tupdate_user_profile(input: {\n\t\tfull_name: \"King Wu 321\"\n\t}, profileFile: $file) {\n\t\t_id\n\t\tupdated_at\n\t\tname\n\t\tcreated_at\n\t\tprofile_image {\n\t\t\t_id\n\t\t\turl\n\t\t}\n\t}\n}"}
Screenshot 2024-07-01 at 1 56 52 AM

KingWu avatar Jun 30 '24 17:06 KingWu

Finally, found that the middleware handle multipart, which has error

Fixed by the following

// Ensure the form is parsed correctly
		if r.Method == http.MethodPost || r.Method == http.MethodPut {
			if r.Header.Get("Content-Type") == "multipart/form-data" {
				if err := r.ParseMultipartForm(32 << 20); err != nil && err != http.ErrNotMultipart {
					http.Error(w, "Failed to parse multipart form", http.StatusBadRequest)
					return
				}
			} else {
				r.ParseForm()
			}
		} else {
			r.ParseForm()
		}

KingWu avatar Jul 01 '24 15:07 KingWu