// MultipartForm reads a multipart form request and deserializes its data and
// files into a struct you provide. Files should be deserialized into
// *multipart.FileHeader fields.
425288
func MultipartForm(req *http.Request, userStruct FieldMapper) error {
	err := multipartFormBinder(req, userStruct)
	if len(err) > 0 {
		return err
	}

	return nil
}
904258
func (this *HttpClient) Post(url string, params interface{}) (*Response,
	error) {
	paramsValues := toUrlValues(params)
	// Post with files should be sent as multipart.
	if checkParamFile(paramsValues) {
		return this.PostMultipart(url, params)
	}

	headers := make(map[string]string)
	headers["Content-Type"] = "application/x-www-form-urlencoded"
	body := strings.NewReader(paramsValues.Encode())

	return this.Do("POST", url, headers, body)
}
380171
func NewUploadPackResponse(req *UploadPackRequest) *UploadPackResponse {
	isShallow := !req.Depth.IsZero()
	isMultiACK := req.Capabilities.Supports(capability.MultiACK) ||
		req.Capabilities.Supports(capability.MultiACKDetailed)

	return &UploadPackResponse{
		isShallow:  isShallow,
		isMultiACK: isMultiACK,
	}
}
825875
func FileHandlerFunc(filePath string) func(http.ResponseWriter, *http.Request) {
	return func(responseWriter http.ResponseWriter, request *http.Request) {
		http.ServeFile(responseWriter, request, filePath)
	}
}
830080
func (req *Request) GetMultipartForm() (ServerMultipartForm, error) {
	if form, err := req.In.Get(HTTP_MULTIPART_FORM); err != nil {
		return nil, err
	} else if values, found := form.(ServerMultipartForm); found {
		return values, nil
	}
	return nil, FORM_NOT_FOUND
}
405623
func (builder *MultipartBuilder) WriteFileHeader(partName string, fileHeader *multipart.FileHeader) error {
	file, err := fileHeader.Open()
	if err != nil {
		return err
	}
	defer file.Close()
	return builder.WriteFileReader(partName, fileHeader.Filename, file)
}
301059
func getMultipartOverhead() int64 {
	multipartOnce.Do(func() {
		var b bytes.Buffer
		w := multipart.NewWriter(&b)
		part, _ := w.CreateFormFile("0", "0")

		dummyContents := []byte("0")
		part.Write(dummyContents)

		w.Close()
		multipartOverhead = int64(b.Len()) - 3 // remove what was added
	})
	return multipartOverhead
}
629816
func ParseFromHeader(req *http.Request, format Format, u ...json.Unmarshaler) (JWS, error) {
	if b, ok := fromHeader(req); ok {
		return parseJumpTable[format](b, u...)
	}
	return nil, ErrNoTokenInRequest
}
1198106
func Files(files []FormFile) p.Plugin {
	return p.NewRequestPlugin(func(ctx *c.Context, h c.Handler) {
		data := FormData{Files: files}
		handle(ctx, h, data)
	})
}
1203145
func (f Form) Bytes(b []byte) []byte {
	src := inputBytes(b)
	ft := formTable[f]
	n, ok := ft.quickSpan(src, 0, len(b), true)
	if ok {
		return b
	}
	out := make([]byte, n, len(b))
	copy(out, b[0:n])
	rb := reorderBuffer{f: *ft, src: src, nsrc: len(b), out: out, flushF: appendFlush}
	return doAppendInner(&rb, n)
}
472427
func (b *Bucket) Multi(ctx context.Context, key, contType string, perm ACL) (MultiInt, error) {
	multis, _, err := b.ListMulti(ctx, key, "")
	if err != nil && !hasCode(err, "NoSuchUpload") {
		if !UsingFakeS3(ctx) {
			return nil, err
		}
		// fakes3 returns NoSuchKey instead of NoSuchUpload, and we want to continue
		// in that case, not abort
		if !hasCode(err, "NoSuchKey") {
			return nil, err
		}
	}
	for _, m := range multis {
		if m.Key == key {
			return m, nil
		}
	}

	return b.InitMulti(ctx, key, contType, perm)
}
168040
func FileUploadFromGlob(fileSystemGlob string) ([]FileUpload, error) {
	files, err := filepath.Glob(fileSystemGlob)

	if err != nil {
		return nil, err
	}

	if len(files) == 0 {
		return nil, errors.New("grequests: No files have been returned in the glob")
	}

	filesToUpload := make([]FileUpload, 0, len(files))

	for _, f := range files {
		if s, err := os.Stat(f); err != nil || s.IsDir() {
			continue
		}

		// ignoring error because I can stat the file
		fd, _ := os.Open(f)

		filesToUpload = append(filesToUpload, FileUpload{FileContents: fd, FileName: filepath.Base(fd.Name())})

	}

	return filesToUpload, nil

}
1314519
func (m *Message) multipartRequest(pToken, rToken, url string) (*http.Request, error) {
	body := &bytes.Buffer{}

	if m.attachment == nil {
		return nil, ErrMissingAttachement
	}

	// Write the body as multipart form data
	w := multipart.NewWriter(body)

	// Write the file in the body
	fw, err := w.CreateFormFile("attachment", "attachment")
	if err != nil {
		return nil, err
	}

	written, err := io.Copy(fw, m.attachment)
	if err != nil {
		return nil, err
	}

	if written > MessageMaxAttachementByte {
		return nil, ErrMessageAttachementTooLarge
	}

	// Handle params
	for k, v := range m.toMap(pToken, rToken) {
		if err := w.WriteField(k, v); err != nil {
			return nil, err
		}
	}

	if err := w.Close(); err != nil {
		return nil, err
	}

	req, err := http.NewRequest("POST", url, body)
	if err != nil {
		return nil, err
	}
	req.Header.Set("Content-Type", w.FormDataContentType())

	return req, nil
}
1130165
func (c *Context) FormFile(name string) (*multipart.FileHeader, error) {
	if c.Request.MultipartForm == nil {
		if err := c.Request.ParseMultipartForm(c.engine.MaxMultipartMemory); err != nil {
			return nil, err
		}
	}
	_, fh, err := c.Request.FormFile(name)
	return fh, err
}
950979
func ProcessPostedFiles(r *http.Request, sfHandler SingleFileHandler) error {

	// parse multipart data
	err := r.ParseMultipartForm(100000)
	if err != nil {
		return err
	}

	// open files
	files := r.MultipartForm.File["file"]
	log.Println("ProcessPostedFiles: got " + strconv.Itoa(len(files)) + " files")
	for i, _ := range files {
		if result, err := sfHandler(files[i]); !result {
			if err != nil {
				return err
			}
			return errors.New("Operation canceled")
		}
	}
	log.Println("ProcessPostedFiles: finished")
	return nil
}
1239231
func (c Client) completeMultipartUpload(ctx context.Context, bucketName, objectName, uploadID string,
	complete completeMultipartUpload) (completeMultipartUploadResult, error) {
	// Input validation.
	if err := s3utils.CheckValidBucketName(bucketName); err != nil {
		return completeMultipartUploadResult{}, err
	}
	if err := s3utils.CheckValidObjectName(objectName); err != nil {
		return completeMultipartUploadResult{}, err
	}

	// Initialize url queries.
	urlValues := make(url.Values)
	urlValues.Set("uploadId", uploadID)
	// Marshal complete multipart body.
	completeMultipartUploadBytes, err := xml.Marshal(complete)
	if err != nil {
		return completeMultipartUploadResult{}, err
	}

	// Instantiate all the complete multipart buffer.
	completeMultipartUploadBuffer := bytes.NewReader(completeMultipartUploadBytes)
	reqMetadata := requestMetadata{
		bucketName:       bucketName,
		objectName:       objectName,
		queryValues:      urlValues,
		contentBody:      completeMultipartUploadBuffer,
		contentLength:    int64(len(completeMultipartUploadBytes)),
		contentSHA256Hex: sum256Hex(completeMultipartUploadBytes),
	}

	// Execute POST to complete multipart upload for an objectName.
	resp, err := c.executeMethod(ctx, "POST", reqMetadata)
	defer closeResponse(resp)
	if err != nil {
		return completeMultipartUploadResult{}, err
	}
	if resp != nil {
		if resp.StatusCode != http.StatusOK {
			return completeMultipartUploadResult{}, httpRespToErrorResponse(resp, bucketName, objectName)
		}
	}

	// Read resp.Body into a []bytes to parse for Error response inside the body
	var b []byte
	b, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		return completeMultipartUploadResult{}, err
	}
	// Decode completed multipart upload response on success.
	completeMultipartUploadResult := completeMultipartUploadResult{}
	err = xmlDecoder(bytes.NewReader(b), &completeMultipartUploadResult)
	if err != nil {
		// xml parsing failure due to presence an ill-formed xml fragment
		return completeMultipartUploadResult, err
	} else if completeMultipartUploadResult.Bucket == "" {
		// xml's Decode method ignores well-formed xml that don't apply to the type of value supplied.
		// In this case, it would leave completeMultipartUploadResult with the corresponding zero-values
		// of the members.

		// Decode completed multipart upload response on failure
		completeMultipartUploadErr := ErrorResponse{}
		err = xmlDecoder(bytes.NewReader(b), &completeMultipartUploadErr)
		if err != nil {
			// xml parsing failure due to presence an ill-formed xml fragment
			return completeMultipartUploadResult, err
		}
		return completeMultipartUploadResult, completeMultipartUploadErr
	}
	return completeMultipartUploadResult, nil
}
1036171
func MakeXMPPFormatter(name string) MessageFormatter {
	return func(m message.Composer) (string, error) {
		return fmt.Sprintf(completeFormatTmpl, name, m.Priority(), m.String()), nil
	}
}