Skip to content

Commit

Permalink
Merge pull request #71 from northseadl/feature/httpRequest
Browse files Browse the repository at this point in the history
add multipart filememe
  • Loading branch information
Matrix-X authored Jan 7, 2023
2 parents b87f2cb + 8dfdf3e commit d56b3ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions http/contract/dataflowInterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ResponseHelper interface {
type MultipartDfInterface interface {
Boundary(b string) MultipartDfInterface
FileByPath(fieldName string, filePath string) MultipartDfInterface
FileMem(fieldName string, fileName string, reader io.Reader) MultipartDfInterface
Part(header textproto.MIMEHeader, reader io.Reader) MultipartDfInterface
FieldValue(fieldName string, value string) MultipartDfInterface
Field(fieldName string, reader io.Reader) MultipartDfInterface
Expand Down
17 changes: 17 additions & 0 deletions http/dataflow/mutlipart.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@ func (m *MultipartDf) FileByPath(fieldName string, filePath string) contract.Mul
return m
}

func (m *MultipartDf) FileMem(fieldName string, fileName string, reader io.Reader) contract.MultipartDfInterface {
writer, err := m.mWriter.CreateFormFile(fieldName, fileName)
if err != nil {
m.errs = append(m.errs, errors.Wrap(err, "create file part failed"))
}
var buf bytes.Buffer
_, err = buf.ReadFrom(reader)
if err != nil {
m.errs = append(m.errs, errors.Wrap(err, "create file part failed"))
}
_, err = buf.WriteTo(writer)
if err != nil {
m.errs = append(m.errs, errors.Wrap(err, "create file part failed"))
}
return m
}

func (m *MultipartDf) Part(header textproto.MIMEHeader, reader io.Reader) contract.MultipartDfInterface {
writer, err := m.mWriter.CreatePart(header)
if err != nil {
Expand Down

0 comments on commit d56b3ad

Please sign in to comment.