当前位置: 首页>>代码示例>>Golang>>正文


Golang Writer.CreateFormFile方法代码示例

本文整理汇总了Golang中mime/multipart.Writer.CreateFormFile方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.CreateFormFile方法的具体用法?Golang Writer.CreateFormFile怎么用?Golang Writer.CreateFormFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mime/multipart.Writer的用法示例。


在下文中一共展示了Writer.CreateFormFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: sendSnapFile

func sendSnapFile(snapPath string, snapFile *os.File, pw *io.PipeWriter, mw *multipart.Writer, action *actionData) {
	defer snapFile.Close()

	if action.SnapOptions == nil {
		action.SnapOptions = &SnapOptions{}
	}
	errs := []error{
		mw.WriteField("action", action.Action),
		mw.WriteField("name", action.Name),
		mw.WriteField("snap-path", action.SnapPath),
		mw.WriteField("channel", action.Channel),
		mw.WriteField("devmode", strconv.FormatBool(action.DevMode)),
	}
	for _, err := range errs {
		if err != nil {
			pw.CloseWithError(err)
			return
		}
	}

	fw, err := mw.CreateFormFile("snap", filepath.Base(snapPath))
	if err != nil {
		pw.CloseWithError(err)
		return
	}

	_, err = io.Copy(fw, snapFile)
	if err != nil {
		pw.CloseWithError(err)
		return
	}

	mw.Close()
	pw.Close()
}
开发者ID:dholbach,项目名称:snappy,代码行数:35,代码来源:snap_op.go

示例2: Write

func Write(w *multipart.Writer, params map[string][]string) error {

	for key, param1 := range params {
		param := param1[0]
		if len(param) > 0 && param[0] == '@' {
			file := param[1:]
			fw, err := w.CreateFormFile(key, file)
			if err != nil {
				log.Println("CreateFormFile failed:", err)
				return err
			}
			fd, err := os.Open(file)
			if err != nil {
				log.Println("Open file failed:", err)
				return err
			} else {
				_, err = io.Copy(fw, fd)
				fd.Close()
				if err != nil {
					log.Println("Copy file failed:", err)
					return err
				}
			}
		} else {
			err := w.WriteField(key, param)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
开发者ID:shtlee,项目名称:qa,代码行数:32,代码来源:multipart.go

示例3: PostWithMultiPartData

func (r Client) PostWithMultiPartData(req_url string, headers map[string][]string, params map[string][]string, body io.Reader, filename string) (resp *http.Response, err error) {
	var buffer *bytes.Buffer = new(bytes.Buffer)
	var writer *multipart.Writer = multipart.NewWriter(buffer)
	for k, v := range params {
		for _, field := range v {
			err1 := writer.WriteField(k, field)
			if err1 != nil {
				err = err1
				return
			}
		}
	}
	w, err := writer.CreateFormFile("file", filename)
	if err != nil {
		return
	}
	_, err = io.Copy(w, body)
	if err != nil {
		return
	}
	err = writer.Close()
	if err != nil {
		return
	}
	if headers == nil {
		headers = make(map[string][]string)
	}
	headers["Content-Type"] = []string{writer.FormDataContentType()}
	return r.Post(req_url, headers, buffer, int64(buffer.Len()))
}
开发者ID:first-developer,项目名称:golang-utils,代码行数:30,代码来源:rpc.go

示例4: addFileReader

func addFileReader(w *multipart.Writer, f *File) error {
	part, err := w.CreateFormFile(f.ParamName, f.Name)
	if err != nil {
		return err
	}
	_, err = io.Copy(part, f.Reader)

	return err
}
开发者ID:tjyang,项目名称:resty,代码行数:9,代码来源:client.go

示例5: addFormFileFromData

// Add a file to a multipart writer.
func addFormFileFromData(writer *multipart.Writer, name, path string, data []byte) error {
	part, err := writer.CreateFormFile(name, filepath.Base(path))
	if err != nil {
		return err
	}

	_, err = part.Write(data)
	return err
}
开发者ID:tingin,项目名称:go-httpclient,代码行数:10,代码来源:util.go

示例6: writeMultiPartFiles

// writeMultiPartFiles writes the given files as parts of a multipart message
// using the given writer.
func writeMultiPartFiles(writer *multipart.Writer, files map[string][]byte) error {
	for fileName, fileContent := range files {

		fw, err := writer.CreateFormFile(fileName, fileName)
		if err != nil {
			return err
		}
		io.Copy(fw, bytes.NewBuffer(fileContent))
	}
	return nil
}
开发者ID:davecheney,项目名称:gomaasapi,代码行数:13,代码来源:client.go

示例7: createArtifactsForm

func (n *GitLabClient) createArtifactsForm(mpw *multipart.Writer, reader io.Reader, baseName string) error {
	wr, err := mpw.CreateFormFile("file", baseName)
	if err != nil {
		return err
	}

	_, err = io.Copy(wr, reader)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:bssthu,项目名称:gitlab-ci-multi-runner,代码行数:12,代码来源:gitlab.go

示例8: writeMPBody

func writeMPBody(fname string, mw *multipart.Writer) error {
	fw, _ := mw.CreateFormFile("files[]", filepath.Base(fname))
	f, err := os.Open(fname)
	if err != nil {
		return err
	}
	defer f.Close()

	_, err = io.Copy(fw, f)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:rd-2bees,项目名称:docker,代码行数:15,代码来源:upload_test.go

示例9: addFile

func addFile(w *multipart.Writer, fieldName, path string) error {
	file, err := os.Open(path)
	if err != nil {
		return err
	}
	defer file.Close()

	part, err := w.CreateFormFile(fieldName, filepath.Base(path))
	if err != nil {
		return err
	}
	_, err = io.Copy(part, file)

	return err
}
开发者ID:gssdromen,项目名称:resty,代码行数:15,代码来源:client.go

示例10: addFile

// addFile adds a file to this multipart form
func addFile(w *multipart.Writer, filePath string) error {
	f, err := os.Open(filePath)
	if err != nil {
		return err
	}
	fw, err := w.CreateFormFile("file", filePath)
	if err != nil {
		return err
	}
	_, err = io.Copy(fw, f)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:intfrr,项目名称:sendto,代码行数:16,代码来源:net.go

示例11: CreateFileForm

func CreateFileForm(bodyWriter *multipart.Writer, fkey, fp string) error {
	fileWriter, err := bodyWriter.CreateFormFile(fkey, fp)
	if err != nil {
		return err
	}
	fh, err := os.Open(fp)
	if err != nil {
		return err
	}
	defer fh.Close()
	_, err = io.Copy(fileWriter, fh)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:Centny,项目名称:Cny4go,代码行数:16,代码来源:http.go

示例12: addFormFile

func addFormFile(writer *multipart.Writer, name string, reader io.Reader) error {
	items := strings.Split(name, ":")
	fieldname := items[0]
	filename := items[1]

	part, err := writer.CreateFormFile(fieldname, filename)
	if err != nil {
		return err
	}

	_, err = io.Copy(part, reader)
	if err != nil {
		return err
	}

	return nil
}
开发者ID:pjozog,项目名称:asciinema,代码行数:17,代码来源:http.go

示例13: encodeChunkedFirstTransmission

func (a *BuyActivity) encodeChunkedFirstTransmission(log bitwrk.Logger, mwriter *multipart.Writer) (err error) {
	part, err := mwriter.CreateFormFile("a32chunks", "a32chunks.bin")
	if err != nil {
		return
	}
	log.Printf("Sending work chunk hashes to seller [%v].", *a.tx.WorkerURL)
	err = cafs.WriteChunkHashes(a.workFile, part)
	if err != nil {
		return
	}
	log.Printf("Sending buyer's secret to seller.")
	err = mwriter.WriteField("buyersecret", a.buyerSecret.String())
	if err != nil {
		return
	}
	return mwriter.Close()
}
开发者ID:psyvisions,项目名称:bitwrk,代码行数:17,代码来源:buy.go

示例14: gradeRun

func gradeRun(
	ctx *common.Context,
	client *http.Client,
	run *common.Run,
	multipartWriter *multipart.Writer,
) (*runner.RunResult, error) {
	ctx.EventCollector.Add(ctx.EventFactory.NewEvent(
		"grade",
		common.EventBegin,
		common.Arg{"id", run.AttemptID},
		common.Arg{"input", run.InputHash},
		common.Arg{"language", run.Language},
	))
	defer func() {
		ctx.EventCollector.Add(ctx.EventFactory.NewEvent(
			"grade",
			common.EventEnd,
		))
	}()

	// Make sure no other I/O is being made while we grade this run.
	ioLockEvent := ctx.EventFactory.NewCompleteEvent("I/O lock")
	ioLock.Lock()
	defer ioLock.Unlock()
	ctx.EventCollector.Add(ioLockEvent)

	inputEvent := ctx.EventFactory.NewCompleteEvent("input")
	input, err := inputManager.Add(
		run.InputHash,
		runner.NewRunnerInputFactory(client, &ctx.Config),
	)
	if err != nil {
		return nil, err
	}
	defer input.Release(input)
	ctx.EventCollector.Add(inputEvent)

	// Send the header as soon as possible to avoid a timeout.
	filesWriter, err := multipartWriter.CreateFormFile("file", "files.zip")
	if err != nil {
		return nil, err
	}

	return runner.Grade(ctx, filesWriter, run, input, &minijail)
}
开发者ID:lhchavez,项目名称:quark,代码行数:45,代码来源:main.go

示例15: write

func (h *baseUploadHandler) write(mpw *multipart.Writer) error {
	logf("Uploading base of %s...", h.filepath)

	var diff *FileDiff
	for _, d := range h.op.patch {
		if d.Path == h.filepath {
			diff = d
			break
		}
	}
	if diff == nil {
		return fmt.Errorf("file %s is not part of patch", h.filepath)
	}

	fields := map[string]string{
		"filename":   h.filepath,
		"status":     string(diff.Op),
		"is_binary":  "false",
		"is_current": "false",
		"checksum":   h.op.baseMD5[h.filepath],
	}

	//"file_too_large": "1",

	if err := writeFields(mpw, fields); err != nil {
		return err
	}

	data, err := mpw.CreateFormFile("data", h.filepath)
	if err != nil {
		return err
	}

	if diff.Op == Added {
		return nil
	}

	base, err := h.op.delta.Base(h.filepath)
	if err != nil {
		return err
	}
	_, err = io.Copy(data, base)
	base.Close()
	return err
}
开发者ID:lambdaX,项目名称:rsc.godev,代码行数:45,代码来源:rietveld.go


注:本文中的mime/multipart.Writer.CreateFormFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。