mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 07:56:14 -06:00
more tests
This commit is contained in:
parent
0def23b2b5
commit
6d3efd3511
2 changed files with 171 additions and 12 deletions
|
|
@ -34,18 +34,21 @@ import (
|
|||
// req.Header.Set("Content-Type", w.FormDataContentType())
|
||||
func CreateMultipartFormData(fieldName string, fileName string, extraFields map[string]string) (bytes.Buffer, *multipart.Writer, error) {
|
||||
var b bytes.Buffer
|
||||
var err error
|
||||
|
||||
w := multipart.NewWriter(&b)
|
||||
var fw io.Writer
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return b, nil, err
|
||||
}
|
||||
if fw, err = w.CreateFormFile(fieldName, file.Name()); err != nil {
|
||||
return b, nil, err
|
||||
}
|
||||
if _, err = io.Copy(fw, file); err != nil {
|
||||
return b, nil, err
|
||||
|
||||
if fileName != "" {
|
||||
file, err := os.Open(fileName)
|
||||
if err != nil {
|
||||
return b, nil, err
|
||||
}
|
||||
if fw, err = w.CreateFormFile(fieldName, file.Name()); err != nil {
|
||||
return b, nil, err
|
||||
}
|
||||
if _, err = io.Copy(fw, file); err != nil {
|
||||
return b, nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for k, v := range extraFields {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue