本文整理汇总了Golang中mime/multipart.Writer.CreateFormField方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.CreateFormField方法的具体用法?Golang Writer.CreateFormField怎么用?Golang Writer.CreateFormField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mime/multipart.Writer
的用法示例。
在下文中一共展示了Writer.CreateFormField方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SendMediaRequest
func SendMediaRequest(client *twittergo.Client, reqUrl string, params map[string]string, media []byte) (mediaResp twittergo.MediaResponse, err error) {
var (
req *http.Request
resp *twittergo.APIResponse
body io.ReadWriter = bytes.NewBufferString("")
mp *multipart.Writer
writer io.Writer
contentType string
)
mp = multipart.NewWriter(body)
for key, value := range params {
mp.WriteField(key, value)
}
if media != nil {
if writer, err = mp.CreateFormField("media"); err != nil {
return
}
writer.Write(media)
}
contentType = fmt.Sprintf("multipart/form-data;boundary=%v", mp.Boundary())
mp.Close()
if req, err = http.NewRequest("POST", reqUrl, body); err != nil {
return
}
req.Header.Set("Content-Type", contentType)
if resp, err = client.SendRequest(req); err != nil {
return
}
err = resp.Parse(&mediaResp)
return
}
示例2: mwSet
func mwSet(mw *multipart.Writer, key, value string) error {
pw, err := mw.CreateFormField(key)
if err != nil {
return err
}
if _, err = pw.Write([]byte(value)); err != nil {
return err
}
return nil
}
示例3: WriteFormData
func WriteFormData(bw *multipart.Writer, FormData map[string]string) error {
for key, value := range FormData {
formFieldWriter, err := bw.CreateFormField(key)
if err != nil {
return err
}
formFieldWriter.Write([]byte(value))
}
return nil
}
示例4: addField
// addField adds a field to the multipart writer
func addField(w *multipart.Writer, k, v string) error {
fw, err := w.CreateFormField(k)
if err != nil {
return err
}
_, err = fw.Write([]byte(v))
if err != nil {
return err
}
return nil
}
示例5: addField
func addField(w *multipart.Writer, fieldName string, value []byte) error {
fw, err := w.CreateFormField(fieldName)
if err != nil {
return err
}
_, err = fw.Write(value)
return err
}
示例6: writeFileField
func writeFileField(w *multipart.Writer, fieldsubid string, filePath string) error {
ff, err := w.CreateFormField(fieldsubid)
if err != nil {
return err
}
file, err := os.Open(filePath)
if err != nil {
return err
}
if _, err := io.Copy(ff, file); err != nil {
return err
}
return nil
}
示例7: writeMultiPartParams
// writeMultiPartParams writes the given parameters as parts of a multipart
// message using the given writer.
func writeMultiPartParams(writer *multipart.Writer, parameters url.Values) error {
for key, values := range parameters {
for _, value := range values {
fw, err := writer.CreateFormField(key)
if err != nil {
return err
}
buffer := bytes.NewBufferString(value)
io.Copy(fw, buffer)
}
}
return nil
}