Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When I read data in the upload file interface, an error message "http: invalid Read on closed Body" is reported #1001

Open
jake12138 opened this issue Aug 6, 2024 · 0 comments

Comments

@jake12138
Copy link

I define a interface:

  /upload/image:
    post:
      requestBody:
        content:
          # a binary file of type png or jpeg
          'image/jpeg':
            schema:
              type: string
              format: binary
      responses:
        200:
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Response"
func init() {
	openapi3filter.RegisterBodyDecoder("image/jpeg", openapi3filter.FileBodyDecoder)
	openapi3filter.RegisterBodyDecoder("image/png", openapi3filter.FileBodyDecoder)
}

func(s *Server) PostUploadImage(ctx context.Context, request PostUploadImageRequestObject) (PostUploadImageResponseObject, error) {
	var buf []byte
	size, err := request.Body.Read(buf)
	if err != nil {
		return nil, errors.Msg("").Extend(err).Code(1)
	}
	fmt.Println(size, buf)
	return PostUploadImage200JSONResponse{}, nil
}

When executing request.Body.Read(buf), an error "http: invalid Read on closed Body" is returned. I am not familiar with kin-openapi, and I want to know how to get the correct data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant