Added UploadMediaFromReader
This commit is contained in:
parent
efa05aa949
commit
e804ee7eb2
3 changed files with 42 additions and 1 deletions
13
status.go
13
status.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue