Skip to content

[question] Error converting into []byte or []uint8 #191

Open
@nikbanerjee-unity

Description

@nikbanerjee-unity

Describe the problem you're having

Schema fails to convert into []uint8 despite it being listed as supported. Anyone aware of why this might be the case? Or if Im misunderstanding the scenario.

I have a server that accepts a multipart/form-data form data, of which one of the fields is a []byte, but when trying to decode into it I get the error:

schema: error converting value for index 0 of "<value>"

Versions

Go version: go version go1.18.1 darwin/arm64

Gorilla version: github.com/gorilla/schema v1.2.0

"Show me the code!"

Minimal test to show this failing:

	req, err := http.NewRequest(http.MethodGet, "todo", nil)
	req.ParseForm()
	req.Form.Set("test1", "anyvalue")

	type demo struct {
		Test1 []byte // I've tried with pointer to byte slice and uint8 slice
	}

	var d demo
	err = formDecoder.Decode(&d, req.Form)
	fmt.Printf("%v", err)

Go playground example: https://go.dev/play/p/e_62qC5zkik

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions