Documentation
¶
Overview ¶
Package upload builds multipart/form-data bodies for catalog requests that send files, and the synthetic files they send when no real file is named: a minimal valid file of a kind (CSV, XLSX, PNG, PDF…), the same bytes every time, holding no data of anyone.
Index ¶
- Constants
- func Encode(fields [][2]string, files []Part) (body []byte, contentType string, err error)
- func FileName(kind string) string
- func KindOf(nameOrExt, mediaType string) string
- func Kinds() []string
- func Known(kind string) bool
- func MediaType(kind string) string
- func Synthetic(kind string) ([]byte, error)
- type Part
Constants ¶
const ( CSV = "csv" XLSX = "xlsx" TXT = "txt" JSON = "json" PNG = "png" JPEG = "jpeg" GIF = "gif" PDF = "pdf" )
Synthetic kinds.
Variables ¶
This section is empty.
Functions ¶
func Encode ¶
Encode writes a multipart/form-data body: the fields in order, then the files. The boundary is derived from the content, so the same request is the same bytes on every capture, and it never occurs in the content. The body is written into a buffer sized for it up front, never grown.
func KindOf ¶
KindOf picks the synthetic kind that stands in for a file, from its media type or its name (an extension or a Laravel mimes: value); "" when none fits.
Types ¶
type Part ¶
type Part struct {
Field string
Name string // file name sent in Content-Disposition
Type string // Content-Type of the part
Data []byte
Open func() (io.ReadCloser, error) // when Data is nil
Size int64 // of what Open gives
}
Part is one file of a multipart body: Data, or what Open gives, which is read twice (to name the boundary, then into the body), so a large file is not held besides the body.