mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-05-06 21:41:37 +00:00
fix(adaptor): 修复解析multipart请求时获取boundary的问题
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"mime"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -129,7 +130,15 @@ func buildRequestBodyWithMappedModel(originalBody []byte, contentType, redirecte
|
|||||||
newBuffer := &bytes.Buffer{}
|
newBuffer := &bytes.Buffer{}
|
||||||
writer := multipart.NewWriter(newBuffer)
|
writer := multipart.NewWriter(newBuffer)
|
||||||
|
|
||||||
r := multipart.NewReader(bytes.NewReader(originalBody), strings.TrimPrefix(contentType, "multipart/form-data; boundary="))
|
_, params, err := mime.ParseMediaType(contentType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "parse_content_type_failed")
|
||||||
|
}
|
||||||
|
boundary, ok := params["boundary"]
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("boundary_not_found_in_content_type")
|
||||||
|
}
|
||||||
|
r := multipart.NewReader(bytes.NewReader(originalBody), boundary)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
part, err := r.NextPart()
|
part, err := r.NextPart()
|
||||||
|
|||||||
Reference in New Issue
Block a user