本文整理汇总了Golang中github.com/mattermost/platform/model.Client.UploadPostAttachment方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.UploadPostAttachment方法的具体用法?Golang Client.UploadPostAttachment怎么用?Golang Client.UploadPostAttachment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/mattermost/platform/model.Client
的用法示例。
在下文中一共展示了Client.UploadPostAttachment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: uploadTestFile
func uploadTestFile(Client *model.Client, channelId string) ([]string, error) {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("files", "test.png")
if err != nil {
return nil, err
}
// base 64 encoded version of handtinywhite.gif from http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
file, _ := base64.StdEncoding.DecodeString("R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs=")
if _, err := io.Copy(part, bytes.NewReader(file)); err != nil {
return nil, err
}
field, err := writer.CreateFormField("channel_id")
if err != nil {
return nil, err
}
if _, err := field.Write([]byte(channelId)); err != nil {
return nil, err
}
if err := writer.Close(); err != nil {
return nil, err
}
if resp, err := Client.UploadPostAttachment(body.Bytes(), writer.FormDataContentType()); err != nil {
return nil, err
} else {
return resp.Data.(*model.FileUploadResponse).Filenames, nil
}
}