github.com/rzurga/go-swagger@v0.28.1-0.20211109195225-5d1f453ffa3a/examples/file-server/restapi/operations/uploads/upload_file_parameters.go (about) 1 // Code generated by go-swagger; DO NOT EDIT. 2 3 package uploads 4 5 // This file was generated by the swagger tool. 6 // Editing this file might prove futile when you re-run the swagger generate command 7 8 import ( 9 "io" 10 "mime/multipart" 11 "net/http" 12 13 "github.com/go-openapi/errors" 14 "github.com/go-openapi/runtime" 15 "github.com/go-openapi/runtime/middleware" 16 ) 17 18 // UploadFileMaxParseMemory sets the maximum size in bytes for 19 // the multipart form parser for this operation. 20 // 21 // The default value is 32 MB. 22 // The multipart parser stores up to this + 10MB. 23 var UploadFileMaxParseMemory int64 = 32 << 20 24 25 // NewUploadFileParams creates a new UploadFileParams object 26 // 27 // There are no default values defined in the spec. 28 func NewUploadFileParams() UploadFileParams { 29 30 return UploadFileParams{} 31 } 32 33 // UploadFileParams contains all the bound params for the upload file operation 34 // typically these are obtained from a http.Request 35 // 36 // swagger:parameters uploadFile 37 type UploadFileParams struct { 38 39 // HTTP Request Object 40 HTTPRequest *http.Request `json:"-"` 41 42 /* 43 Required: true 44 In: formData 45 */ 46 File io.ReadCloser 47 } 48 49 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 50 // for simple values it will use straight method calls. 51 // 52 // To ensure default values, the struct must have been initialized with NewUploadFileParams() beforehand. 53 func (o *UploadFileParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 54 var res []error 55 56 o.HTTPRequest = r 57 58 if err := r.ParseMultipartForm(UploadFileMaxParseMemory); err != nil { 59 if err != http.ErrNotMultipart { 60 return errors.New(400, "%v", err) 61 } else if err := r.ParseForm(); err != nil { 62 return errors.New(400, "%v", err) 63 } 64 } 65 66 file, fileHeader, err := r.FormFile("file") 67 if err != nil { 68 res = append(res, errors.New(400, "reading file %q failed: %v", "file", err)) 69 } else if err := o.bindFile(file, fileHeader); err != nil { 70 // Required: true 71 res = append(res, err) 72 } else { 73 o.File = &runtime.File{Data: file, Header: fileHeader} 74 } 75 if len(res) > 0 { 76 return errors.CompositeValidationError(res...) 77 } 78 return nil 79 } 80 81 // bindFile binds file parameter File. 82 // 83 // The only supported validations on files are MinLength and MaxLength 84 func (o *UploadFileParams) bindFile(file multipart.File, header *multipart.FileHeader) error { 85 return nil 86 }