multipart

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongParam = errors.New("wrong param")

but failed to return an explicit error.

Functions

This section is empty.

Types

type OnProgressCallback

type OnProgressCallback func(part VirtualPart, err error, readCount, totalCount int64)

OnProgressCallback provide progress callback when do real POST, it's useful when uploading large files.

Notice: the part is nil and err is EOF when send last end boundary.

type VirtualPart

type VirtualPart interface {
	// Name returns current field name
	Name() string

	// Len returns current part length, include boundary
	Len() int64

	// Remain returns current remain length while reading
	Remain() int64

	// Close closes the part(FilePart)
	Close() error
	// contains filtered or unexported methods
}

VirtualPart handle all the part's content and provide detail information in OnProgressCallback

type VirtualWriter

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

VirtualWriter is similar as builtin mime/multipart.writer, but can support upload lots of files (4G+) with little memory consume.

func NewVirtualWriter

func NewVirtualWriter() *VirtualWriter

NewVirtualWriter returns a new multipart writer with a random boundary,

func (*VirtualWriter) Close

func (vw *VirtualWriter) Close() error

Close closes all the parts

func (*VirtualWriter) ContentLength

func (vw *VirtualWriter) ContentLength() int64

ContentLength return content length for all parts, it should same as "Content-Length" in http header

func (*VirtualWriter) CreateFormFile

func (vw *VirtualWriter) CreateFormFile(fieldName, filePath string) error

CreateFormFile creates a new form-data header with the provided field name and file name. But it just remains the file information, will not read the file contents to memory until actual POST occurs.

func (*VirtualWriter) FormDataContentType

func (vw *VirtualWriter) FormDataContentType() string

FormDataContentType returns the Content-Type for an HTTP multipart/form-data with this Writer's Boundary.

Copy from built-in multipart.Writer #FormDataContentType

func (*VirtualWriter) Read

func (vw *VirtualWriter) Read(p []byte) (nRead int, err error)

Read is used for Reader function(example: body parameter for http.NewRequest), user should NOT call it directly.

func (*VirtualWriter) Seek

func (vw *VirtualWriter) Seek(offset int64, whence int) (int64, error)

used for RepeatableReader, so don't read all contents to memory, must SetCloseAfterRead(false) now just support offset=0 && whence = io.SeekStart

func (*VirtualWriter) SetBoundary

func (vw *VirtualWriter) SetBoundary(boundary string) error

SetBoundary overrides the VirtualWriter's default randomly-generated boundary separator with an explicit value.

Copy from built-in multipart.Writer, and modify for totalCount

func (*VirtualWriter) SetCloseAfterRead

func (vw *VirtualWriter) SetCloseAfterRead(closeAfterRead bool)

SetCloseAfterRead close the part immediately after read the part, it's used in file part, default is true

func (*VirtualWriter) SetProgressCallback

func (vw *VirtualWriter) SetProgressCallback(callback OnProgressCallback)

SetProgressCallback set the callback function

func (*VirtualWriter) WriteField

func (vw *VirtualWriter) WriteField(fieldName, value string) error

WriteField creates a new form-data header with the provided field name and value

Jump to

Keyboard shortcuts

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