multipartx

package
v0.0.0-...-1d1a5ee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileFormBody

func FileFormBody(fieldName, filePath, contentType string, fields map[string]string) (io.Reader, string, error)

FileFormBody opens filePath, adds it as the named file part plus any extra string fields, and returns the completed body and Content-Type.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder constructs multipart/form-data bodies that can be streamed directly to client.DoRaw via RawRequest.Headers["Content-Type"] + RawRequest.Data.

func New

func New() *Builder

New returns a fresh Builder.

func (*Builder) AddField

func (b *Builder) AddField(name, value string) error

AddField appends a non-file form field.

func (*Builder) AddFile

func (b *Builder) AddFile(fieldName, filename string, reader io.Reader, contentType string) error

AddFile appends a file part; the reader is fully drained into the buffer. fieldName and filename must NOT contain `"`, `\`, CR, or LF — values are inserted directly into the Content-Disposition header.

func (*Builder) Build

func (b *Builder) Build() (io.Reader, string, error)

Build closes the multipart writer and returns the final body reader along with the Content-Type (containing the negotiated boundary). The returned io.Reader is single-use, as bytes.Buffer.Read advances internal state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL