mirror of
https://github.com/fumiama/NanoBot.git
synced 2026-06-12 06:00:29 +08:00
fix multipart
This commit is contained in:
25
http.go
25
http.go
@@ -122,11 +122,10 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
h := make(textproto.MIMEHeader)
|
h := make(textproto.MIMEHeader)
|
||||||
h.Set("Content-Disposition",
|
|
||||||
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
|
|
||||||
escapeQuotes(fieldname), escapeQuotes(fieldname)))
|
|
||||||
if rx.Kind() == reflect.Pointer && rx.Elem().Kind() == reflect.Struct { // 使用 json 编码
|
if rx.Kind() == reflect.Pointer && rx.Elem().Kind() == reflect.Struct { // 使用 json 编码
|
||||||
h.Set("Content-Type", "application/octet-stream")
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"`, escapeQuotes(fieldname)))
|
||||||
|
h.Set("Content-Type", "application/json")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
@@ -140,6 +139,9 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
switch o := x.(type) {
|
switch o := x.(type) {
|
||||||
case string:
|
case string:
|
||||||
if strings.HasPrefix(o, "file:///") { // 是文件路径
|
if strings.HasPrefix(o, "file:///") { // 是文件路径
|
||||||
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
|
||||||
|
escapeQuotes(fieldname), escapeQuotes(fieldname)))
|
||||||
h.Set("Content-Type", "application/octet-stream")
|
h.Set("Content-Type", "application/octet-stream")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -157,6 +159,9 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(o, "base64://") { // 是 base64
|
if strings.HasPrefix(o, "base64://") { // 是 base64
|
||||||
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
|
||||||
|
escapeQuotes(fieldname), escapeQuotes(fieldname)))
|
||||||
h.Set("Content-Type", "application/octet-stream")
|
h.Set("Content-Type", "application/octet-stream")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -169,6 +174,9 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(o, "base16384://") { // 是 base16384
|
if strings.HasPrefix(o, "base16384://") { // 是 base16384
|
||||||
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
|
||||||
|
escapeQuotes(fieldname), escapeQuotes(fieldname)))
|
||||||
h.Set("Content-Type", "application/octet-stream")
|
h.Set("Content-Type", "application/octet-stream")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -180,6 +188,9 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"`, escapeQuotes(fieldname)))
|
||||||
|
h.Set("Content-Type", "application/json")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
@@ -190,6 +201,9 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
case []byte:
|
case []byte:
|
||||||
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"; filename="%s"`,
|
||||||
|
escapeQuotes(fieldname), escapeQuotes(fieldname)))
|
||||||
h.Set("Content-Type", "application/octet-stream")
|
h.Set("Content-Type", "application/octet-stream")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -201,6 +215,9 @@ func WriteBodyByMultipartFormData(params ...any) (*bytes.Buffer, string, error)
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
|
h.Set("Content-Disposition",
|
||||||
|
fmt.Sprintf(`form-data; name="%s"`, escapeQuotes(fieldname)))
|
||||||
|
h.Set("Content-Type", "application/json")
|
||||||
r, err := w.CreatePart(h)
|
r, err := w.CreatePart(h)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user