From babd795d792e95f6e708af6ee8207ef6877e2b32 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 20 Feb 2018 10:41:00 -0500 Subject: 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 --- model/client4.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'model/client4.go') 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 { -- cgit v1.2.3-1-g7c22