Add UploadMediaFromBytes function
parent
309dce6ff3
commit
e5c082de35
|
@ -409,7 +409,12 @@ func (c *Client) UploadMedia(ctx context.Context, file string) (*Attachment, err
|
||||||
return c.UploadMediaFromMedia(ctx, &Media{File: f})
|
return c.UploadMediaFromMedia(ctx, &Media{File: f})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UploadMediaFromReader uploads a media attachment from a io.Reader.
|
// UploadMediaFromBytes uploads a media attachment from a byte slice.
|
||||||
|
func (c *Client) UploadMediaFromBytes(ctx context.Context, b []byte) (*Attachment, error) {
|
||||||
|
return c.UploadMediaFromReader(ctx, bytes.NewReader(b))
|
||||||
|
}
|
||||||
|
|
||||||
|
// UploadMediaFromReader uploads a media attachment from an io.Reader.
|
||||||
func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error) {
|
func (c *Client) UploadMediaFromReader(ctx context.Context, reader io.Reader) (*Attachment, error) {
|
||||||
return c.UploadMediaFromMedia(ctx, &Media{File: reader})
|
return c.UploadMediaFromMedia(ctx, &Media{File: reader})
|
||||||
}
|
}
|
||||||
|
|
|
@ -708,6 +708,18 @@ func TestUploadMedia(t *testing.T) {
|
||||||
if writerAttachment.ID != "123" {
|
if writerAttachment.ID != "123" {
|
||||||
t.Fatalf("want %q but %q", "123", attachment.ID)
|
t.Fatalf("want %q but %q", "123", attachment.ID)
|
||||||
}
|
}
|
||||||
|
bytes, err := os.ReadFile("testdata/logo.png")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not open file: %v", err)
|
||||||
|
}
|
||||||
|
byteAttachment, err := client.UploadMediaFromBytes(context.Background(), bytes)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if byteAttachment.ID != "123" {
|
||||||
|
t.Fatalf("want %q but got %q", "123", attachment.ID)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetConversations(t *testing.T) {
|
func TestGetConversations(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue