Skip to content

Commit

Permalink
add multipart filememe
Browse files Browse the repository at this point in the history
  • Loading branch information
northseadl committed Jan 7, 2023
1 parent 91252d2 commit 8dfdf3e
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 8dfdf3e

Please sign in to comment.