diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2018-02-20 10:41:00 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-20 10:41:00 -0500 |
commit | babd795d792e95f6e708af6ee8207ef6877e2b32 (patch) | |
tree | 32116afb6e1ea7b598c41eaddb318cea8fabd132 /model | |
parent | f85d9105925a82c5006654b99060506a0ff7d7af (diff) | |
download | chat-babd795d792e95f6e708af6ee8207ef6877e2b32.tar.gz chat-babd795d792e95f6e708af6ee8207ef6877e2b32.tar.bz2 chat-babd795d792e95f6e708af6ee8207ef6877e2b32.zip |
MM-9556 Added ability to upload files without a multipart request (#8306)
* MM-9556 Added ability to upload files without a multipart request
* MM-9556 Handled some unusual test behaviour
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/model/client4.go b/model/client4.go index 962b816bb..4772d38b3 100644 --- a/model/client4.go +++ b/model/client4.go @@ -1915,7 +1915,8 @@ func (c *Client4) DoPostAction(postId, actionId string) (bool, *Response) { // File Section -// UploadFile will upload a file to a channel, to be later attached to a post. +// UploadFile will upload a file to a channel using a multipart request, to be later attached to a post. +// This method is functionally equivalent to Client4.UploadFileAsRequestBody. func (c *Client4) UploadFile(data []byte, channelId string, filename string) (*FileUploadResponse, *Response) { body := &bytes.Buffer{} writer := multipart.NewWriter(body) @@ -1939,6 +1940,12 @@ func (c *Client4) UploadFile(data []byte, channelId string, filename string) (*F return c.DoUploadFile(c.GetFilesRoute(), body.Bytes(), writer.FormDataContentType()) } +// UploadFileAsRequestBody will upload a file to a channel as the body of a request, to be later attached +// to a post. This method is functionally equivalent to Client4.UploadFile. +func (c *Client4) UploadFileAsRequestBody(data []byte, channelId string, filename string) (*FileUploadResponse, *Response) { + return c.DoUploadFile(c.GetFilesRoute()+fmt.Sprintf("?channel_id=%v&filename=%v", url.QueryEscape(channelId), url.QueryEscape(filename)), data, http.DetectContentType(data)) +} + // GetFile gets the bytes for a file by id. func (c *Client4) GetFile(fileId string) ([]byte, *Response) { if r, err := c.DoApiGet(c.GetFileRoute(fileId), ""); err != nil { |