// SetForm creates form and add files and data to form.
SetForm creates form and add files and data to form.
// SetForm creates form and add files and data to form .
func (r *Req) SetForm(files []map[string]string, fields []map[string]string) *Req {
	if r.err != nil {
		return r
	}
	var b bytes.Buffer
	w := multipart.NewWriter(&b)
	for _, file := range files {
		for key, value := range file {
			if err := createFormFile(w, key, value); err != nil {
				logger.Errorf("Failed to create form file %s as %s Error: %v", key, value, err)
				r.err = err
				return r
			}
		}
	}
	for _, field := range fields {
		for k, v := range field {
			err := w.WriteField(k, v)
			if err != nil {
				logger.Errorf("Can't write field %s as %s Error: %v", k, v, err)
				r.err = err
				return r
			}
		}
	}
	if err := w.Close(); err != nil {
		logger.Errorf("Can't close multipart writer Error: %v", err)
		r.err = err
		return r
	}
	r.request.Body = ioutil.NopCloser(bytes.NewReader(b.Bytes()))
	r.request.GetBody = func() (io.ReadCloser, error) {
		return ioutil.NopCloser(bytes.NewReader(b.Bytes())), nil
	}
	r.request.ContentLength = int64(b.Len())
	r.request.Header.Set("Content-Type", w.FormDataContentType())
	return r
}
func ( r * Req ) SetForm ( files [ ] map [ string ] string , fields [ ] map [ string ] string ) * Req { if r . err != nil { return r } var b bytes . Buffer w := multipart . NewWriter ( & b ) for _ , file := range files { for key , value := range file { if err := createFormFile ( w , key , value ) ; err != nil { logger . Errorf ( " " , key , value , err ) r . err = err return r } } } for _ , field := range fields { for k , v := range field { err := w . WriteField ( k , v ) if err != nil { logger . Errorf ( " " , k , v , err ) r . err = err return r } } } if err := w . Close ( ) ; err != nil { logger . Errorf ( " " , err ) r . err = err return r } r . request . Body = ioutil . NopCloser ( bytes . NewReader ( b . Bytes ( ) ) ) r . request . GetBody = func ( ) ( io . ReadCloser , error ) { return ioutil . NopCloser ( bytes . NewReader ( b . Bytes ( ) ) ) , nil } r . request . ContentLength = int64 ( b . Len ( ) ) r . request . Header . Set ( " " , w . FormDataContentType ( ) ) return r }
SetForm creates form and add files and data to form.
SetForm creates form and add files and data to form .
// If there is an error in chain, then do nothing and return early // GetBody is required to be set for protecting body on redirections