aboutsummaryrefslogtreecommitdiff
path: root/mastodon/mastodon.go
diff options
context:
space:
mode:
Diffstat (limited to 'mastodon/mastodon.go')
-rw-r--r--mastodon/mastodon.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/mastodon/mastodon.go b/mastodon/mastodon.go
index ff86d2b..22f5a53 100644
--- a/mastodon/mastodon.go
+++ b/mastodon/mastodon.go
@@ -83,6 +83,32 @@ func (c *Client) doAPI(ctx context.Context, method string, uri string, params in
return err
}
ct = mw.FormDataContentType()
+ } else if file, ok := params.(*multipart.FileHeader); ok {
+ f, err := file.Open()
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+
+ var buf bytes.Buffer
+ mw := multipart.NewWriter(&buf)
+ part, err := mw.CreateFormFile("file", filepath.Base(file.Filename))
+ if err != nil {
+ return err
+ }
+ _, err = io.Copy(part, f)
+ if err != nil {
+ return err
+ }
+ err = mw.Close()
+ if err != nil {
+ return err
+ }
+ req, err = http.NewRequest(method, u.String(), &buf)
+ if err != nil {
+ return err
+ }
+ ct = mw.FormDataContentType()
} else if reader, ok := params.(io.Reader); ok {
var buf bytes.Buffer
mw := multipart.NewWriter(&buf)