Added UploadMediaFromReader

This commit is contained in:
Brian C. Lindner 2019-03-10 22:55:15 -04:00 committed by mattn
parent efa05aa949
commit e804ee7eb2
3 changed files with 42 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
"net/http"
"net/url"
"time"
"io"
)
// Status is struct to hold status.
@ -265,7 +266,7 @@ func (c *Client) Search(ctx context.Context, q string, resolve bool) (*Results,
return &results, nil
}
// UploadMedia upload a media attachment.
// UploadMedia upload a media attachment from a file.
func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, error) {
var attachment Attachment
err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", file, &attachment, nil)
@ -274,3 +275,13 @@ func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, err
}
return &attachment, nil
}
// UploadMediaFromReader uploads a media attachment from a io.Reader.
func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error) {
var attachment Attachment
err := c.doAPI(ctx, http.MethodPost, "/api/v1/media", reader, &attachment, nil)
if err != nil {
return nil, err
}
return &attachment, nil
}