package client import ( "encoding/base64" "io" "os" ) func NewAttachmentFromFileContent(fileName string, f []byte) (*FileAttachment, error) { buffer := make([]byte, base64.StdEncoding.EncodedLen(len(f))) base64.StdEncoding.Encode(buffer, f) return &FileAttachment{ Filename: fileName, Content: string(buffer), }, nil } func NewAttachmentFromFilePath(filePath string) (*FileAttachment, error) { f, err := os.Open(filePath) if err != nil { return nil, err } defer func(f *os.File) { _ = f.Close() }(f) content, err := io.ReadAll(f) if err != nil { return nil, err } return NewAttachmentFromFileContent(filePath, content) }