File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,13 +5,21 @@ import (
55 "fmt"
66 "io"
77 "mime/multipart"
8+ "net/textproto"
89 "strings"
910)
1011
12+ var quoteEscaper = strings .NewReplacer ("\\ " , "\\ \\ " , `"` , "\\ \" " )
13+
14+ func escapeQuotes (s string ) string {
15+ return quoteEscaper .Replace (s )
16+ }
17+
1118type DiscordFile struct {
1219 * bytes.Buffer
1320 Filename string
1421 Description string
22+ ContentType string
1523 Spoiler bool
1624}
1725
@@ -40,8 +48,18 @@ func (f *DiscordFile) GenerateAttachment(index Snowflake, m *multipart.Writer) (
4048 Filename : f .Filename ,
4149 Description : f .Description ,
4250 }
51+ contentType := "application/octet-stream"
52+ if f .ContentType != "" {
53+ contentType = f .ContentType
54+ }
55+
56+ h := make (textproto.MIMEHeader )
57+ h .Set ("Content-Disposition" ,
58+ fmt .Sprintf (`form-data; name="%s"; filename="%s"` ,
59+ escapeQuotes (fmt .Sprintf (formFieldNameFmt , index )), escapeQuotes (f .Filename )))
60+ h .Set ("Content-Type" , contentType )
4361
44- w , err := m .CreateFormFile ( fmt . Sprintf ( formFieldNameFmt , index ), f . Filename )
62+ w , err := m .CreatePart ( h )
4563 if err != nil {
4664 return nil , err
4765 }
You can’t perform that action at this time.
0 commit comments