-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go): Add MultipartWriter w/ Content-Type (#5131)
- Loading branch information
Showing
296 changed files
with
47,481 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package core | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
// FileParam is a file type suitable for multipart/form-data uploads. | ||
type FileParam struct { | ||
io.Reader | ||
filename string | ||
contentType string | ||
} | ||
|
||
// FileParamOption adapts the behavior of the FileParam. No options are | ||
// implemented yet, but this interface allows for future extensibility. | ||
type FileParamOption interface { | ||
apply() | ||
} | ||
|
||
// NewFileParam returns a *FileParam type suitable for multipart/form-data uploads. All file | ||
// upload endpoints accept a simple io.Reader, which is usually created by opening a file | ||
// via os.Open. | ||
// | ||
// However, some endpoints require additional metadata about the file such as a specific | ||
// Content-Type or custom filename. FileParam makes it easier to create the correct type | ||
// signature for these endpoints. | ||
func NewFileParam( | ||
reader io.Reader, | ||
filename string, | ||
contentType string, | ||
opts ...FileParamOption, | ||
) *FileParam { | ||
return &FileParam{ | ||
Reader: reader, | ||
filename: filename, | ||
contentType: contentType, | ||
} | ||
} | ||
|
||
func (f *FileParam) Name() string { return f.filename } | ||
func (f *FileParam) ContentType() string { return f.contentType } |
Oops, something went wrong.