github.com/Bio-core/jtree@v0.0.0-20190705165106-1d7a7e7d6272/restapi/operations/post_upload_parameters.go (about) 1 package operations 2 3 // This file was generated by the swagger tool. 4 // Editing this file might prove futile when you re-run the swagger generate command 5 6 import ( 7 "io" 8 "mime/multipart" 9 "net/http" 10 11 "github.com/go-openapi/errors" 12 "github.com/go-openapi/runtime" 13 "github.com/go-openapi/runtime/middleware" 14 ) 15 16 // NewPostUploadParams creates a new PostUploadParams object 17 // with the default values initialized. 18 func NewPostUploadParams() PostUploadParams { 19 var () 20 return PostUploadParams{} 21 } 22 23 // PostUploadParams contains all the bound params for the post upload operation 24 // typically these are obtained from a http.Request 25 // 26 // swagger:parameters PostUpload 27 type PostUploadParams struct { 28 29 // HTTP Request Object 30 HTTPRequest *http.Request `json:"-"` 31 32 /*The file to upload. 33 In: formData 34 */ 35 Upfile io.ReadCloser `json:"upfile"` 36 37 //Filename is the name of the uploaded file 38 Filename string 39 } 40 41 // BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface 42 // for simple values it will use straight method calls 43 func (o *PostUploadParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error { 44 var res []error 45 o.HTTPRequest = r 46 47 if err := r.ParseMultipartForm(32 << 20); err != nil { 48 if err != http.ErrNotMultipart { 49 return err 50 } else if err := r.ParseForm(); err != nil { 51 return err 52 } 53 } 54 55 upfile, upfileHeader, err := r.FormFile("upfile") 56 if err != nil && err != http.ErrMissingFile { 57 res = append(res, errors.New(400, "reading file %q failed: %v", "upfile", err)) 58 } else if err == http.ErrMissingFile { 59 // no-op for missing but optional file parameter 60 } else if err := o.bindUpfile(upfile, upfileHeader); err != nil { 61 res = append(res, err) 62 } else { 63 o.Upfile = &runtime.File{Data: upfile, Header: upfileHeader} 64 } 65 o.Filename = upfileHeader.Filename 66 67 if len(res) > 0 { 68 return errors.CompositeValidationError(res...) 69 } 70 return nil 71 } 72 73 func (o *PostUploadParams) bindUpfile(file multipart.File, header *multipart.FileHeader) error { 74 75 return nil 76 }