Merge pull request #234 from dmportella/sendfile-enhancement
Sendfile enhancement
This commit is contained in:
commit
9011830676
1 changed files with 16 additions and 0 deletions
16
restapi.go
16
restapi.go
|
@ -1218,12 +1218,28 @@ func (s *Session) ChannelMessagesPinned(channelID string) (st []*Message, err er
|
||||||
|
|
||||||
// ChannelFileSend sends a file to the given channel.
|
// ChannelFileSend sends a file to the given channel.
|
||||||
// channelID : The ID of a Channel.
|
// channelID : The ID of a Channel.
|
||||||
|
// name: The name of the file.
|
||||||
// io.Reader : A reader for the file contents.
|
// io.Reader : A reader for the file contents.
|
||||||
func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (st *Message, err error) {
|
func (s *Session) ChannelFileSend(channelID, name string, r io.Reader) (st *Message, err error) {
|
||||||
|
return s.ChannelFileSendWithMessage(channelID, "", name, r)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChannelFileSendWithMessage sends a file to the given channel with an message.
|
||||||
|
// channelID : The ID of a Channel.
|
||||||
|
// content: Optional Message content.
|
||||||
|
// name: The name of the file.
|
||||||
|
// io.Reader : A reader for the file contents.
|
||||||
|
func (s *Session) ChannelFileSendWithMessage(channelID, content string, name string, r io.Reader) (st *Message, err error) {
|
||||||
|
|
||||||
body := &bytes.Buffer{}
|
body := &bytes.Buffer{}
|
||||||
bodywriter := multipart.NewWriter(body)
|
bodywriter := multipart.NewWriter(body)
|
||||||
|
|
||||||
|
if len(content) != 0 {
|
||||||
|
if err := bodywriter.WriteField("content", content); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
writer, err := bodywriter.CreateFormFile("file", name)
|
writer, err := bodywriter.CreateFormFile("file", name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue